需要将我的正则表达式更改为特殊字符 [英] Need to change my Regular expression for special characters

查看:88
本文介绍了需要将我的正则表达式更改为特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有一个正则表达式来检查密码中密码的任何地方是否至少有一个字符和一个特殊字符.因此,我使用了以下正则表达式,

I need to have a regular expression to check if the password has atleast one character and one special character anywhere in the password. Hence i used the below regular expression,

if (!System.Text.RegularExpressions.Regex.IsMatch(a, "^(?=.*[#@].*)(?=.*[a-zA-Z].*)[a-zA-Z0-9#@]{6,15}$"))
{...}



但是此正则表达式不允许特殊字符位于密码的末尾.例如,它允许test!6767,但不允许test6767!.

请告诉我我应该在外部表达式中做些什么

谢谢



But this regular expression doesnot allow the special character to be last of the password. Say for example, it allows test!6767 but it doesnot allow test6767!.

Please tell me what i change i should do in the external expression

Thanks

推荐答案

")) {...}
")) {...}



但是此正则表达式不允许特殊字符位于密码的末尾.举例来说,它允许test!6767,但不允许test6767!.

请告诉我我应该在外部表达式中做些什么

谢谢



But this regular expression doesnot allow the special character to be last of the password. Say for example, it allows test!6767 but it doesnot allow test6767!.

Please tell me what i change i should do in the external expression

Thanks


从我对问题的回答
From my answer to the question How to verify a password which contain .......[^]
(?=^.{8})(?=.*[a-z])(?=.*[A-Z])(?=.*[^\w\d])(?=.*\d).*




(?=^.{8})
最小长度

(?=.*[a-z])
验证至少一个小写字符

(?=.*[A-Z])
验证至少一个大写字符

(?=.*[^\w\d])
验证至少一个特殊字符

(?=.*\d)
验证至少一位数字



(?=^.{8})
The minimum length

(?=.*[a-z])
Verify atleast one lowercase character

(?=.*[A-Z])
Verify atleast one uppercase character

(?=.*[^\w\d])
Verify atleast one special character

(?=.*\d)
Verify atleast one digit


这篇关于需要将我的正则表达式更改为特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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