7.1 Javascript: Forms and validation-length verification

Source: Internet
Author: User

What kind of method should be used to remind users? You certainly don't want to use the alert () Prompt box

Add a Sqan tag after entering the field

<input id="Phone"Name="Phone"  Type="Text"Size=" A"Onblur="Validatenonemptyfun (This,document.getelementbyid (' phone_help ')");/><span id="Phone_help" class="Help"></span>functionValidate_length (Inputfiled,helptext) {//If the input field content is empty, alert within the span tag    if(inputfiled.value.length==0)    {if(helptext!=NULL) helptext.innerhtml="text box cannot be empty"; }//Empty the contents of the span tag if the input field is not empty    Else if(helptext!=NULL) helptext.innerhtml=""}</script>

HelpText is an incoming span object
Use span tags to remind users that they don't block user vision like alert

In addition to non-null validation, there are dimension issues

Verify data length

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

Here the parameters become four, the first is the minimum length of text, the second is the longest length of text

function Validate_length (minlegth,maxlength,inputfiled, HelpText) {if(inputfiled.value.length<minlegth| | Inputfiled.value.length>maxlength) {if( HelpText!=null) { HelpText.innerhtml="Please enter a length of"+minlenght+"to"+maxlength+"Text";return false; }    }Else if( HelpText!=null) { HelpText.innerhtml=""        return true; }    }
Verify postal code
function Validate_zipcode (inputfiled, HelpText) {if(inputfiled.value.length!=5)    {if( HelpText!=null) HelpText.innerhtml="ZIP code must be 5-bit long";return false; }Else if(IsNaN (Inputfiled.value)) {if( HelpText!=null) HelpText.innerhtml="ZIP code must be a number";return false; }Else if( HelpText!=null) { HelpText.innerhtml=""        return true; }    }

7.1 Javascript: Forms and validation-length 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.