密码必须是8个字符,其中包括1个大写字母,特殊字符,字母数字字符 [英] Password must be 8 characters including 1 uppercase letter, 1 special character, alphanumeric characters

查看:9568
本文介绍了密码必须是8个字符,其中包括1个大写字母,特殊字符,字母数字字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个普通的前pression检查

I want a regular expression to check that

,密码必须八个字符,包括一个大写字母,一个特殊字符和字母数字字符。

a password must be eight characters including one uppercase letter, one special character and alphanumeric characters.

和这里是我的验证前pression这是八个字符,包括一个大写字母,一个小写字母和一个数字或特殊字符。

And here is my validation expression which is for eight characters including one uppercase letter, one lowercase letter, and one number or special character.

(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$"

我怎么能写为必须是八个字符,包括一个大写字母,一个特殊字符和字母数字字符?

How I can write it for a password that must be eight characters including one uppercase letter, one special character and alphanumeric characters?

推荐答案

常规前pression你以后最有可能是巨大的和一个噩梦特别是维护的人谁不熟悉与常规的前pressions。

The regular expression you are after will most likely be huge and a nightmare to maintain especially for people who are not that familiar with regular expressions.

我想这会更容易打破你的正则表达式下来,做一个位在一个时间。这可能需要多一点的事,但我pretty确保维护它和调试它会更容易。这也将允许您提供更直接的错误信息给用户,应改善用户体验。

I think it would be easier to break your regex down and do it one bit at a time. It might take a bit more to do, but I am pretty sure that maintaining it and debugging it would be easier. This would also allow you to provide more directed error messages to your users (other than just Invalid Password) which should improve user experience.

这是我所看到的你是pretty精通正则表达式,所以我会presume,给予你的常规前pressions做你需要的都将是徒劳的。

From what I am seeing you are pretty fluent in regex, so I would presume that giving you the regular expressions to do what you need would be futile.

看到你的评论,我这是怎么会去一下:

Seeing your comment, this is how I would go about it:


  • 必须是八个字符长:你并不需要这样的正则表达式。使用。长度属性应该是足够了。

包括一个大写字母:您可以使用 [A-Z] + 常规EX pression。如果字符串包含至少一个大写字母,此正前pression将产生真正

Including one uppercase letter: You can use the [A-Z]+ regular expression. If the string contains at least one upper case letter, this regular expression will yield true.

一个特殊字符:您可以使用 \\ W 将匹配这不是一个字母或数字或其他任何字符,你可以使用的东西像这样 [!@#] 指定的特殊字符的自定义列表。不过,请注意字符如 $ ^ 是在常规的前pression语言的特殊字符,所以需要进行转义像这样: \\ $ 。因此,在短期,你可以使用 \\ W

One special character: You can use either the \W which will match any character which is not a letter or a number or else, you can use something like so [!@#] to specify a custom list of special characters. Note though that characters such as $, ^, ( and ) are special characters in the regular expression language, so they need to be escaped like so: \$. So in short, you might use the \W.

字母数字字符:使用 \\ w + 应匹配任何字母和数字和下划线

Alphanumeric characters: Using the \w+ should match any letter and number and underscore.

看看本教程的更多信息。

这篇关于密码必须是8个字符,其中包括1个大写字母,特殊字符,字母数字字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆