开发者

Need help with a regular expression for ColdFusion

开发者 https://www.devze.com 2023-03-15 04:53 出处:网络
I would love some help with a regular expression that tests a string for a few things. I need the user to enter a value that is at least 10 characters in length, contains at least 1 number, at le开发

I would love some help with a regular expression that tests a string for a few things.

I need the user to enter a value that is at least 10 characters in length, contains at least 1 number, at le开发者_开发技巧ast 1 special character, and at least 1 upper case letter.

Any help would be greatly appreciated.

Thanks!


Just have a separate regex for each of the constraints:

  • at least 10 characters in length: .{10,},
  • contains at least 1 number: [0-9],
  • at least 1 special character: [^0-9a-zA-Z]
  • at least 1 upper case letter: [A-Z]

And make sure that the string matches all of these regexes.

If you really need it, you can combine them all in one regex, using lookahead assertions: (?=.*[0-9])(?=.*[^0-9a-zA-Z])(?=.*[A-Z]).{10,}


The length requirement is probably easier to test without a regex. The other tests would work better as separate tests as well:

number: [0-9]+

upper case: [A-Z]+

special (punctuation characters): [[:punct:]]+

trying to combine them into one regex would probably yield something rather unwieldy, and unclear

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号