开发者

Editing a regex that isn't mine, not sure how to adjust it for needs

开发者 https://www.devze.com 2023-02-28 18:40 出处:网络
I have a regex that was written for me for passwords: ~^[a-z0-9!@#\\$%\\^&\\*\\(\\)]{8,16}$~i It\'s supposed to match strings of alphanumerics and symbols of 8-16 characters.Now I need to remov

I have a regex that was written for me for passwords:

~^[a-z0-9!@#\$%\^&\*\(\)]{8,16}$~i

It's supposed to match strings of alphanumerics and symbols of 8-16 characters. Now I need to remove the min and max length requirement as I need to split the error messages for user friendliness - I trie开发者_JAVA技巧d to just take out the {8,16} portion but then it breaks it. How would I do this? Thanks ahead of time.


I take it you're doing separate checks for too-long or too-short strings, and this regex is only making sure there are no invalid characters. This should do it:

~^[a-z0-9!@#$%^&*()]+$~i

+ means one or more, * means zero or more; it probably doesn't matter which one you use.

I got rid of some unnecessary backslashes, too; none of those characters has any special meaning in a character class (inside the square brackets, that is).

0

精彩评论

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

关注公众号