ASP. net mvc & amp; JQuery application (Form Verification)

Source: Internet
Author: User

In this example, the Jquery Validation plug-in is called to make data verification more convenient and convenient. There are two display modes.

Display the prompt information behind each item

$ ("# Test-form"). validate ({submitHandler: function () {alert ("submitted successfully! ")}});

Display the prompt information in the top information box

$ ("# Test-form"). validate ({

ErrorLabelContainer: "# ErrMessageBox ",

Wrapper: "li ",

SubmitHandler: function () {alert ("submitted successfully! ")} // Call the method after verification

});

Use custom verification methods

// Two Chinese characters

JQuery. validator. addMethod ("rangelength", function (value, element, param ){

Var length = value. length;

For (var I = 0; I <value. length; I ++ ){

If (value. charCodeAt (I)> 127 ){

Length ++;

}

}

Return this. optional (element) | (length> = param [0] & length <= param [1]);

}, "The input value must be 3-15 bytes. ");

Call a custom Verification Method

$ ("# Password"). rules ("add ",{

Required: true,

Rangelength: [6, 50], // call the method defined above

Messages :{

Required: "The password cannot be blank. ",

Rangelength: "The password must be between 6 and 50 characters. "

}

});

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.