我正在使用JQuery来验证表单,并希望selectedUsername字段只接受不带空格的字母数字字符。我似乎找不到这样做的规则 - 我该怎么办?
$('.theForm').validate({
errorElement: 'label', //default input error message container
errorClass: 'help-inline', // default input error message class
focusInvalid: false, // do not focus the last invalid input
ignore: "",
rules: {
chosenUsername: {
required: true,
minlength: 4
}
},
messages: { // custom messages for radio buttons and checkboxes
message: {
required: "Please enter a username of at least 4 characters.",
minlength: "Minimum of 4 characters."
}
},
谢谢! 仲裁器
答案 0 :(得分:2)
试试这个:
jQuery.validator.addMethod("alphanumeric", function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
});
参考this