JQuery Validate Regex Password Validation

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

I have been reading about how to manipulate regex, and I do think I have the correct formula for my purpose, but I cannot seem to get it to work.

This is my code

$.validator.addMethod("pwcheck", function(value) {     var regex = /^[a-zA-Z0-9]*$/;     if (!regex.test(value)) {         return false;     } }); 

I added this method to my password in the .validate({rules{}}); It is linked properly, but whatever I input in the text box I get the message I wrote in the .validate({messages{}}); the user should be only allowed to input letters and numbers, and seeing other methods posted on this site I tried to mimic and copy them, but it isn't working.

回答1:

$.validator.addMethod("pwcheck", function(value) {    return /^[A-Za-z0-9]*$/.test(value) }); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!