Javascript Form Verification length, javascript form

Source: Internet
Author: User

Javascript Form Verification length, javascript form

JavaScript can be used 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

<Input id = "phone" name = "phone" type = "text" size = "12" onBlur = "validateNonEmptyFun (this, document. getElementById ('phone _ help'); "/> <span id =" phone_help "class =" help "> </span> function validate_Length (inputFiled, helpText) {// if the input field content is empty, 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

<input id="phone" name="phone" type="text" size="12" onBlur="validate_Length(1,32,this,document.getElementById('phone_help'));" /><span id="phone_help" class="help"></span>

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 (minLegth, maxlength, inputFiled, helpText) {if (inputFiled. value. length <minLegth | 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 ;}}

Articles you may be interested in:
  • Regular Expressions for JavaScript form verification [recommended]
  • Practical JS Form Verification tips
  • Javascript Regular Expression Form Verification Code
  • Getting started with jquery validate. js Form Verification
  • Simple js form verification functions
  • Js uses regular expressions to verify the form (relatively complete resources)
  • Javascript Form Verification example (javascript verification email)
  • Extjs form common verification Summary
  • Jquery Form Verification plug-in (jquery. validate. js)
  • Form Verification of simple registration module made by javascript

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.