为密码验证C#正则表达式 [英] Regular Expression for Password Validation C#

查看:165
本文介绍了为密码验证C#正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#中使用正则表达式验证密码

I want to validate a password using regular expression in c#.

这些条件:


  1. 不应该用数字或特殊字符

  2. 开始不应该有特殊字符结尾

  3. 必须包含所有这三个在至少一次(@,#,_),并没有其他特殊字符。

  4. 必须至少包含一个字母

  5. 必须至少包含一个数字

  6. 长度应为最小8字符

  1. should not start with digit or special character
  2. should not end with special character
  3. must contain any of these three at least once('@','#','_') and no other special characters are allowed.
  4. must contain at least one letter
  5. must contain at least one digit
  6. length should be minimum 8 character

下面是我的尝试:?

^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#_])

我知道它甚至还没有接近满足上述条件。所以请任何人都可以修改此正则表达式,使其满足上述所有条件。

I know it is not even close to satisfy the above mentioned conditions. So please can anyone modify this regex so that it satisfies all the above conditions.

先谢谢了。

推荐答案

给这个一抡

^(?i)(?=.*[a-z])(?=.*[0-9])(?=.*[@#_])[a-z][a-z0-9@#_]{6,}[a-z0-9]$

适合你的规范,我相信。从当前的正则表达式的外观youll能理解,但如果没有发表评论和虐待解释。

Fits your specification I believe. From the look of your current regex youll be able to understand it but if not comment and ill explain.

这篇关于为密码验证C#正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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