密码正则表达式允许 ©单词末尾的符号

发布于 2024-12-09 06:51:21 字数 419 浏览 2 评论 0原文

我使用以下正则表达式来确保密码仅包含字母和数字字符。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紫罗兰の梦幻 2024-12-16 06:51:21

您的正则表达式仅确保第一个字符是字母数字和/或标点符号。您需要确保每个字符都是字母数字和/或标点符号。您可以使用其中任何一个:(

if(reFind("[^[:alnum:][:punct:]]", this.password))

if(! reFind("^[[:alnum:][:punct:]]*$", this.password))

注意:这些也与您的不同,因为它们允许零长度密码。我认为这没关系,因为在这种情况下您会想要给出不同的错误消息。)

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:

if(reFind("[^[:alnum:][:punct:]]", this.password))

if(! reFind("^[[:alnum:][:punct:]]*$", this.password))

(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.)

心房的律动 2024-12-16 06:51:21

试试这个:

if(!reFind("^[[:alnum:][:punct:]]+$", this.password))

Try this:

if(!reFind("^[[:alnum:][:punct:]]+$", this.password))
娇妻 2024-12-16 06:51:21

为什么你不能写这样的东西:

^[0-9a-zA-Z]+$

why can't you write something like:

^[0-9a-zA-Z]+$
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文