Java Script Basics (11) Form validation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.