Javascript Form Verification length _ javascript skills

Source: Internet
Author: User
JavaScript can be used to verify the input data in the HTML form before the data is sent to the server. This article introduces the length of Javascript form verification. For more information, see JavaScript to verify the input data in the HTML form before the data is sent to the server.

What method should we use to remind users? You do not want to use the alert () Prompt box

Add an sqan label after the input field

Function validate_Length (inputFiled, helpText) {// if the content of the input field is null, the if (inputFiled. value. length = 0) {if (helpText! = Null) helpText. innerHTML = "text box cannot be blank";} // if the input field is not empty, the else if (helpText! = Null) helpText. innerHTML = ""} script

HelpText is the input span object.

The span label is used to remind users. It does not block user vision as alert does.

Besides non-empty verification, there are also dimensional problems

Verify Data Length

 

Here the parameter is changed to four, the first is the minimum length of the text, and the second is the maximum length of the text.

Function validate_Length (minleworkflow, maxlength, inputFiled, helpText) {if (inputFiled. value. length
 
  
Maxlength) {if (helpText! = Null) {helpText. innerHTML = "Enter the length of" + minLenght + "to" + maxLength + "text"; return false ;}} else if (helpText! = Null) {helpText. innerHTML = "" return true ;}}
 

Verify zip code

Function validate_ZipCode (inputFiled, helpText) {if (inputFiled. value. length! = 5) {if (helpText! = Null) helpText. innerHTML = "the zip code must be 5 characters long"; return false;} else if (isNaN (inputFiled. value) {if (helpText! = Null) helpText. innerHTML = "the zip code must be a number"; return false;} else if (helpText! = Null) {helpText. innerHTML = "" return true ;}}

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.