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. "
}
});