It has an onsubmit event attached to a function called validate() that we are going to create later inside this form there are three inputs one for our phone number another one is for postal codes and the third and the last one is a submit button that is going to submit the form after we are done filling it. It contains only the code that validates the phone number.
In the first line, I am using Element By Id() to grab the phone number from the input element.
For ‘selections’ like drop down and radio group, use an appropriate validation like ‘dontselect’ or ‘selone_radio’.
This validation descriptor is valid only for drop down lists.
The “validation descriptor” is nothing but a string specifying the type of validation to be performed.
Each field in the form can have zero one or more validations. More info & downloads where Do My Validation One() and Do My Validation Two() are custom functions for validation.
So, most of the web developers prefer Java Script form validation.
There are many more rules but let's leave it at these basic rules.
First go to your html file and paste the following code : Here, I have a simple form.
Now let’s jump into the fun part which is discussing the regular expression First we have the starting and ending slashes “/” , the expression then starts with a “^” sign to match with the beginning of the string.
Notice the [-\s\.] this part matches a hyphen(-) space or a dot (.).[0-9] means 3 digits.
The drop down select list boxes usually will have one item saying ‘Select One’ (and that item will be selected by default).
The user should select an option other than this ‘Select One’ item.