请查看我的代码,checkUser 功能不起作用。我认为 value.match() 函数有错误:
<form id="register_form" method="post" action="">
<fieldset>
<legend>Info</legend>
<div>
<label>Username</label>
<input type="text" name="username" id="username"/>
<input type="submit" id="btnAccess" class="button" value="Submit" name="btnAccess"/>
</fieldset>
</form>
$(document).ready(function() {
var validator = $('#register_form').validate({
rules: {
username: {
required: true,
minlength: 4,
checkUsername: true
}
},
messages: {
username: {
required: "No blank",
minlength: "Enter atleast 4 words"
}
}
});
$.validator.addMethod('checkUsername', function(value, element) {
return this.optional(element) || !/\s/g.test(value) || !value.match(/^ÀÁÂÃÈÉÊÌÍÒÓÔÕÙ+/);
}, "No space or unicode character");
});