字母、数字和特殊字符的正则表达式

发布于 2024-12-05 20:13:44 字数 99 浏览 1 评论 0原文

有人可以给出一个单词的正则表达式,它应该具有:

  1. 长度在6到10范围内
  2. 必须是字母数字、数字和特殊字符(非字母数字字符)的组合

Can someone please give regular expression for a word, which should have:

  1. length in the range of 6 to 10
  2. It must be a combination of alphanumeric, numeric and special character (non-alphanumeric character)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

¢蛋碎的人ぎ生 2024-12-12 20:13:44

换句话说,所有字符都是允许的,但至少需要一个字母、一个数字和一个“其他”字符?

^(?=.*\p{L})(?=.*\p{N})(?=.*[^\p{L}\p{N}]).{6,10}$

不过,我不会对密码施加最大长度限制...

解释:

^                    # Match start of string
(?=.*\p{L})          # Assert that string contains at least one letter
(?=.*\p{N})          # Assert that string contains at least one digit
(?=.*[^\p{L}\p{N}])  # Assert that string contains at least one other character
.{6,10}              # Match a string of length 6-10
$                    # Match end of string

So in other words, all characters are allowed, but at least one letter, one digit, and one "something else" character is required?

^(?=.*\p{L})(?=.*\p{N})(?=.*[^\p{L}\p{N}]).{6,10}$

I wouldn't impose a maximum length restriction on a password, though...

Explanation:

^                    # Match start of string
(?=.*\p{L})          # Assert that string contains at least one letter
(?=.*\p{N})          # Assert that string contains at least one digit
(?=.*[^\p{L}\p{N}])  # Assert that string contains at least one other character
.{6,10}              # Match a string of length 6-10
$                    # Match end of string
雅心素梦 2024-12-12 20:13:44

您应该将其作为一系列连续的测试来执行:

  1. 它的长度合适吗? ^.{6,10}$
  2. 是否包含字母字符? [A-Za-z]
  3. 它包含数字吗? [0-9]
  4. 是否包含“特殊字符” [^0-9A-Za-z]

如果通过了全部四项测试,就可以了。

You should do this as a sequential series of tests:

  1. Is it of the right length? ^.{6,10}$
  2. Does it contain an alphabetic character? [A-Za-z]
  3. Does it contain a digit? [0-9]
  4. Does it contain a "special character" [^0-9A-Za-z]

If it passes all four tests, it's ok.

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