所以我現在有強制執行強密碼這種方法:如何爲用戶名限制創建jQuery Validator方法?
$.validator.addMethod('goodPassword', function(value, element){
return this.optional(element) ||
value.length >= 6 &&
/\d/.test(value) &&
/[a-z]/i.test(value);
}, 'Your password sucks boy, you need at least 6 char and both number and char in that motherf.')
我要創建我的用戶名類似的東西給他們僅侷限於英文字母,數字,破折號,下劃線和句點。我似乎無法弄清楚如何去做。我讀了一些關於正則表達式的知識,但仍然無法弄清楚我應該如何去處理我的代碼。
這是我目前有:
$.validator.addMethod('goodUsername', function(value, element)){
return this.optional(element) ||
value.length >= 4 // && or ||, not really sure what to put here
//something to check if entered data contains anything other than letters, numbers, dashes, underscores and periods
}, 'What kind of fkin username is that? You can only use letters, numbers, dashes, underscores and periods.')
可有人告訴我的方式嗎?
你可以,如果你使用的是用'[\ w .-] {4}'..但是這將允許'.....'或'。 - ...'等 – rock321987