Rogerio Kioshi wrote:I need to validade if a string has 8 characters, at least 1 letter, 1 number and 1 special character. How to write this rule using Regex?
all you need is this regex
but remember from now one , here we are to help you not to provide ready made solutions so from now first show us what you have tried so far then any one would love to solve your problem . k. have a good day bye, put as much special characters you want in the last square bracket.
Just in case it didn't come across, password requirements such as this are ridiculous and make passwords less secure. Who makes up this crap?
The only password restrictions that should ever be in place, in my opinion is a minimum length, and preventing the password from being the same as the username. Anything else is just plain stupid.
Rogerio Kioshi wrote:I need to validade if a string has 8 characters, at least 1 letter, 1 number and 1 special character. How to write this rule using Regex?
all you need is this regex
but remember from now one , here we are to help you not to provide ready made solutions so from now first show us what you have tried so far then any one would love to solve your problem . k. have a good day bye, put as much special characters you want in the last square bracket.
A few issues with the regex....
1. The request was for exactly eight characters -- which is not handled by the regex.
2. I don't think that the requirement "at least 1 letter, 1 number and 1 special character", implies that the special character must come after the number, which must come after the letter -- which the regex requires.
3. I don't think that the plus sign within the character class does what you think it does.
Why do you have to use a single regexp? It would be clearer has a bunch of and statements - one for each rule. Some of those rules owuld be a regexp, but a very simple one.
Michael Parmeley wrote:You could also take advantage of all the special characters being 33-47 decimal (inclusive) in the ascii table.
Are you sure ? Without even looking at an ascii table I can tell you it's not true. 33 - 47 covers a range of 15 characters, but Rogerio has 22 characters in his list of special characters.
Michael Parmeley
Greenhorn
Joined: Aug 20, 2004
Posts: 14
posted
0
Adrian Burkett wrote:
Michael Parmeley wrote:You could also take advantage of all the special characters being 33-47 decimal (inclusive) in the ascii table.
Are you sure ? Without even looking at an ascii table I can tell you it's not true. 33 - 47 covers a range of 15 characters, but Rogerio has 22 characters in his list of special characters.
Indeed, my mistake. Didn't look at it close enough.
Rogerio Kioshi wrote:Thanks for replying. Actually, I gave up using Regex and made a simple method using the following:
I think this way is better for code maintenance.
100% agreed. Being able to understand and maintain the code should be of high priority.... However, just in case you are interested in how a regex would look like...