Recommended reading: JavaScript form verification length
JavaScript Form validation-Submitting a form
JavaScript form Validation-the first recognition of regular expressions
JavaScript form Validation-uncovering the veil of the regular expression
JavaScript can be used to validate these input data in an HTML form before the data is sent to the server.
Check the legality of the data before submitting the form
When you want to verify the data in your form, you can use getElementById () to access any element on the page
Each form field has a Form object that can be passed to any function that validates the form's data
<input id= "ZipCode" name= "ZipCode" type= "text" size= "5" onclick= "Showit (this.form)"/>
function Showit ( Thisform)
{
alert (thisform["ZipCode"].value);
Gets the value of the element through the form object's Name property
Access to elements can be accomplished by using the Name property or the getElementById () method
The timing of checking the form data depends on selecting the correct user input event to process.
That is, the data is validated immediately after the user enters the data.
The order in which users enter data is:
Select input Field
Enter data in a field
Leave the field and move to the next target
Select the next target domain
Enter data in a field
In this process, a series of events are fired, using these events to find the time to validate the data
1 when the input field is selected – Fires the onfocus event (Focus)
2 when leaving the input field – fires the onblur event (leaving the focus)
3 Leave the field and the input content changes – fires the onchange event
The most correct choice is to validate the data when the onblur event is fired
First step of validation: Check that the domain is not empty
<input id= "Phone" name= "Phone" type= "text" size= "" Onblur= "Validatenonempty" (This) "/>
Call Validatenonempty to respond to onblur events
The form object uses the keyword this to be passed to the function
Here is the validation function
function Validatenonempty (Inputfield)
{
if (inputfield.value.length==0)
{
alert ("Please enter a Value. ");
return false;
}
return true;
}
When the Web form is submitted, be sure to validate the data entered by the user
When you want to verify the data in your form, you can use getElementById () to access any element on the page
The above content is for JavaScript form and validation-not NULL verification of all the description, hope to help!