An example of using regular expressions in JavaScript to check that an input consists only of numbers.


Regular expressions are very powerful and can match all kinds of patterns. If you just want to know whether something is a number, you can use parseFloat() and the boolean function isNaN(), as follows:


  1. This work is licensed under a Creative Commons License
  2. Creative Commons License
  3. Viewable With Any
Browser
  4. Valid HTML 4.01!
  5. Valid CSS!