The following is how regular expressions can be used [abc] – find any character in the brackets a, b or c [a-z] – find the range of characters within brackets i.e. Can also be used with numbers [0-9] [^xyz] – find any character other than the ones specified in the brackets i.e.
You can write Java Script scripts to check the following validations.
To get a string contains only numbers (0-9) we use a regular expression (/^[0-9] $/) which allows only numbers.
x,y and z (word) – find the “word” specified in the round brackets [abc|xyz] – find either the characters a,b,c or x,y,z We’ll start first with validating a textbox that accepts only numbers.
So the condition is we check whether the textbox contains anything ELSE other than numbers and display a message As you can see the function validate() checks if the entered string contains characters that does NOT (notice the ^ symbol) match the numbers 0 to 9 including white spaces and special characters.