$.validator.addMethod('AZ09_', function (value) {
return /^[a-zA-Z0-9.-_]+$/.test(value);
}, 'Only letters, numbers, and _-. are allowed');
当我使用test-123
之类的东西时,它仍然会触发,就好像连字符无效一样.我试了\-
和--
$.validator.addMethod('AZ09_', function (value) {
return /^[a-zA-Z0-9.-_]+$/.test(value);
}, 'Only letters, numbers, and _-. are allowed');
当我使用test-123
之类的东西时,它仍然会触发,就好像连字符无效一样.我试了\-
和--
Escaping using \-
should be fine, but you can also try putting it at the beginning or the end of the character class. This should work for you:
/^[a-zA-Z0-9._-]+$/