RegEx验证密码(1小写,1Uppercase,1位数,NoSpaces) [英] RegEx to Validate Password (1 Lowercase, 1Uppercase, 1 Digit, NoSpaces)

查看:175
本文介绍了RegEx验证密码(1小写,1Uppercase,1位数,NoSpaces)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建符合以下条件的RegExpression:

I'm trying to create a RegExpression to meet the criteria below;


  • 至少1小写

  • 至少1个大写

  • 至少1个数字

  • 无空格


  • 没有特殊字符

  • at least 1 Lowercase
  • at least 1 Uppercase
  • at least 1 Digit
  • No Spaces
  • Minimum 8 characters
  • No special characters

到目前为止,我有这个;

So far I got this;

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

上班。
任何帮助将非常感谢。
我从来不善于谜题:)

However I can not get it to work. Any help would be greatly appreciated. I was never good at puzzles :)

推荐答案

它只是忽略了你的无空格/特殊字符规则的结尾处的。* ,而(?=。\s) / code> lookahead是错误的(你可能意味着(?!。* \s)(?= \S * $ ))。

You're nearly there; it's just the .* at the end that ignores your "no spaces/special characters" rules, and the (?=.\s) lookahead is wrong (you probably meant (?!.*\s) or (?=\S*$)).

但是你不需要那么先行,因为你可以简单地指定允许哪些字符(并且强制执行8个字符最小规则):

But you don't need that lookahead anyway because you can simply specify which characters are allowed (and enforce the "8 characters minimum" rule there, too):

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

保持用户在其密码中不使用非字母数字字符?

But why do you want to keep users from using non-alphanumeric characters in their passwords?

这篇关于RegEx验证密码(1小写,1Uppercase,1位数,NoSpaces)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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