Validating numeric value in text field using regex - Javascript RegExp

Javascript examples for RegExp:Match Number

Description

Validating numeric value in text field using regex

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
var re = /^\d*\.?\d$/;/*from w w w  . j  a  v  a  2s .  com*/
var tests = [
  123, 1, 12345, 233.2, 1212.2, 1.1,
  1.222, 1.33, -89789, -3
];
tests.forEach(function(test, i){
  document.write(i, '. ', re.test(test), '<br/>');
});

      </script>  
   </body>
</html>

Related Tutorials