密码正则表达式允许 ©单词末尾的符号
我使用以下正则表达式来确保密码仅包含字母和数字字符。
if(! reFind("^[[:alnum:][:punct:]]", this.password)) {
this.addError(property="Password", message="Password must contain only letters, numbers, or punctuation marks.");
}
如果我在单词的开头添加版权 ©
字符,则 reFind 会阻止它;如果我将它添加到单词的末尾,它就会通过。因此,©abcd
不会通过,而 abcd©
则会通过。
我想确保我的密码中只允许使用字母数字和标点符号。
I'm using the following Regex to ensure that a password only has alphabetic and numeric characters.
if(! reFind("^[[:alnum:][:punct:]]", this.password)) {
this.addError(property="Password", message="Password must contain only letters, numbers, or punctuation marks.");
}
If I add a copyright ©
character to the beginning of the word, the reFind blocks it; if I add it to the end of the word, it goes through. So ©abcd
does not go through, while abcd©
does.
I want to make sure that I only allow alphanumeric and punctuation characters in my passwords.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的正则表达式仅确保第一个字符是字母数字和/或标点符号。您需要确保每个字符都是字母数字和/或标点符号。您可以使用其中任何一个:(
注意:这些也与您的不同,因为它们允许零长度密码。我认为这没关系,因为在这种情况下您会想要给出不同的错误消息。)
Your regular expression just ensures that the first character is alphanumeric and/or punctuation. You want to ensure that every character is alphanumeric and/or punctuation. You can use either of these:
(Note: these also differ from yours in that they allow a zero-length password. I figure that that's O.K., since you'll want to give a different error message in that case.)
试试这个:
Try this:
为什么你不能写这样的东西:
why can't you write something like: