Chapter 9 form validation

Why Form Validation

    1. To reduce the pressure on the server 2. The data input to ensure compliance

 

 

 

Common form validation

  1. Date Format
  2. Whether the form element is empty
  3. user name and password
  4. E-mail address
  5. identification number

Form selector

 

Attribute filter selector

 

Verify the contents of the form:

Use String object verification email: can not be empty, in the correct format.

Verification is not empty:

Search string: indexOf ():

Find the location of a specified string value of the first occurrence of a string

Verify the contents of the text box:

The password can not be empty, no less than six characters, the name can not be empty, we can not have a number.

Length validation:

 

Determining whether the digital string:

Using a for loop and substring () method of sequentially cut a single character, and then determines whether each character is a number

 

Form validation events, and methods

Form validation events, and methods requires a combination of elements:

 

Regular Expressions:

Why do we need a regular expression:

  1. Clean code
  2. Verify the contents of the text box example rigorous:

    Example:

  3. Normal mode:

    var reg = / expression / additional parameters

  4. [Expression must be a constant string]

    [The use of certain additional parameters to represent rules: g represents a global matching may be performed; I representatives case insensitive; m may be representative of a plurality of rows match]

    Constructor: var reg = new RegExp ( "expression", "additional parameters")

  5. Simple mode:

    We can only express specific match

  6. Composite mode: You can use wildcard characters to express more abstract mode of rule

     
  7. Use HTML5 way authentication form:

    HTML5 New Verify attributes:

  8. Example:

  9.  

     

Guess you like

Origin www.cnblogs.com/Chencheno/p/11075242.html