Create Decimal regular expression with zero using regex - Javascript RegExp

Javascript examples for RegExp:Match Number

Description

Create Decimal regular expression with zero using regex

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
var str = 'abc0.06abc';
var newstr = str.replace(/[^0-9.()]/g, '');

if (/^\d*(\.\d+)*$/.test(str) == false) {
   console.log(newstr + " is valid");
}
else {//from w  w w  .j a v a 2  s  .c  o  m
  console.log(newstr + " is not valid");
}

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

Related Tutorials