How to validate decimal numbers in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To validate decimal numbers in JavaScript, use the match() method. It retrieves the matches when matching a string against a regular expression.

Example

You can try to run the following code to validate decimal numbers −

<html>
   <body>
      <script>
         var str = "1.5";
         var re = /^[-+]?[0-9]+\.[0-9]+$/;
         var found = str.match( re );
         document.write("decimal" );
      </script>
   </body>
</html>
raja
Ali
Published on 16-Jan-2018 15:55:17
Advertisements