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: