First, the necessity of forms validation:
Form validation on both the client and server side, client authentication is actually a direct call to the JavaScript script to verify the data entered by the user, and the server can also achieve data validation, but when the server pressure is too large, the resource loss will be more serious, the user experience is not good enough. So it is usually verified that most of us are implemented on the client side, which can reduce the pressure on the server and let the server do other more important things.
Second, the contents of the form verification:
1. Verify that the form contents are empty.
2. Verify whether it is a number.
3. Verify e-mail format.
4. Verify that the data is within a certain range.
5. Verify that the content length entered by the user is sufficient.
These are the validation rules that are common in form validation, and there are other rules that require us to write our own validation rules according to our actual needs.
Third, form elements commonly used properties, methods and events:
Property:
ID: Returns the ID of the text box
Value: Returns the values of the text box
Method:
Blur (): Move focus away from text box
Focus (): Let the text box get focus
Select (): Choose text Box Contents
Event:
onblur (): Triggers when loss of focus
onfocus (): Trigger when get focus
onkeypress (): Press the keyboard and release
Through the above events and methods can set the time for validation of form elements, such as when the focus is lost or the keyboard content is directly verified, so that the user experience better, do not need the user click the Submit button to achieve validation.
Java Script Basics (11) Form validation