If you are running a chat group where users can enter data, for example, you might want to check the input for swear words and replace them with blanks.Or if you're checking input that you will later make part of a database query, you might want to check the data to protect yourself from SQL injection attacks.If you combine the two components, separated by a space, you could use the following regular expression: But this will tell you only that the data the user entered meets the format you defined; it won't tell you whether it's a real phone number.For instance, a string of 1s would pass the validation but is not a phone number in the UK.The first condition is for correct data and returns the message .Then common errors are checked starting with the most specific.The language with the most usage of regular expressions is Perl, which Java Script functionality is derived from, although they are also common in UNIX/Linux scripts.
Regular expressions are relatively new to Java Script, having arrived with Internet Explorer and Netscape Navigator 4.
Sometimes situations arise (input a phone number, zip code or credit card number) when the user should fill a single or more than one fields with numbers (0-9) in an HTML form.
You can write Java Script scripts to check the following validations.
Using a length test eliminates the need for the empty test.
The three functions used in this example go beyond the basic test to test for and report common errors.