Instance:
<!--custom Check form-->$.validator.addmethod ("Checkusername", //Check rule name, similar to Requiredfunction (Value,element, params) {//define a flag flag to mark whether the user name already exists var flag = False;$.ajax ({"Async": false,//must be synchronized here, because asynchronous processing, first executes the return statement, resulting in the inability to effectively return "url": "${pagecontext.request.contextpath}/checkusername", "data": {"username": Value}, "type": " POST "," DataType ":" JSON "," Success ": function (data) {flag = Data.isexist; Indicates whether the user name already exists in the database});//false indicates that the validator does not pass, that is, the user name is already in the database return!flag;}); Where: Value: Indicates the label entered for the check. /element: Indicates the label in which the check is located // params: The parameter that represents the check rule
Customize a validator--------------------------when the user registers, whether the username conforms to the rules and the time already exists in the database checksum