validate custom validation format

<script type="text/javascript">

//custom validation rule
$.validator.addMethod(
//rule name
"checkUsername",
//validation function
function(value,element,params){

//definition A flag
var flag = false;

//value: the input content
//element: the element object to be verified
//params: the parameter value corresponding to the rule
//purpose: perform ajax verification on the input username
$.ajax({
"async":false,
"url":"${pageContext.request.contextPath}/checkUsername",
"data":{"username":value},
"type":"POST",
"dataType":"json" ,
"success":function(data){
flag = data.isExist;
}
});


//Return false means that the validator does not pass
return !flag;
}

);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325254608&siteId=291194637