数据注释的正则表达式

时间:2014-09-17 14:29:45

标签: c# regex

如何为以下

编写正则表达式
at least 6 characters
at least 1 uppercase
at least 1 lowercase
at least 1 number
at least 1 special character ("#¤%&/( æøå etc.)

我尝试了以下正则表达式,但它无效。

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

1 个答案:

答案 0 :(得分:2)

以下正则表达式将满足您的所有条件,

^(?=.{6,})(?=.*?[A-Z])(?=.*?[a-z])(?=.*?\d)(?=.*?\W).*$

DEMO

(?=.{6,})          at least 6 characters
(?=.*?[A-Z])       at least 1 uppercase
(?=.*?[a-z])       at least 1 lowercase
(?=.*?\d)          at least 1 number
(?=.*?\W)          at least 1 non-word character