I need help how to make regex to validate password if it contains at least one character [a-zA-Z] and at least one digit [0-9]??
I look for any digit .*[0-9].* and for any character .*[a-zA-Z]+.* but I don't know how to connect them to search for at least one digit in any position and one character in any position (any appearance of)
^(?=.*\d)(?=.*[a-zA-Z]).{4,8}$ This will check for text string to have atleast one Numeric and one Character and the length of text string to be between 4 to 8 characters.....Try this out...Njoy!
That is great However unfortunatly it do not accept strings like "mypass1" because there is no letter after digit. it is accepting only "my1pass" or "1mypass".
What I need is to do exactly that what do your regex but without important order of appearance
Moreover (i don't know why) but it do not accept string where is more digits then characters like : "35463pas". But it is not a big problem...
Is it possible to make your regex that will ignore the order of appearance?
It was easy;) I googled your regex and I found some similar another versions of that I have combined them :) and I got exactly that what I need without important order of appearance :
Actual Regex is : ^.*(?=.{4,10})(?=.*\d)(?=.*[a-zA-Z]).*$
1) Search for at least one digit in any position
2) Search for at least one upper or lower case in any position
3) Enforce password to consist of 4-10 characters
Now it's exactly what I need;)
THANKS akchamarthy again:)!! I've just added ".*" twice and changed string leanght controlelr??(can it be called like that?) :)
I know this is a nearly-3-year-old post so sorry to post a reply.
Just wanted to say thank you for posting this regular expression. I've spent most of today googling for it, and finally typed just the right thing into Google to find this page :)
I did modify it just slightly; because your regex would allow special characters and space characters. I wanted to validate a username with the rules 1. must be at least six characters; 2. must contain only letters or numbers; 3. must contain at least one
letter.
To solve my problem, I adapted your regex slightly into:
A huge THANX to both akchamarthy
and Dealie for both your examples were exactly what I was looking for to come up with a quick win on a late friday evening issue - I know very little about RegEx, and needed to craft something out of thin air. Wouldn't be able to do it without these
posts. Still good after 5 years!!
It works on all my test cases, except it allows "a1234567890", "testIt!0987", and "1abcdefghijk", none of which should be allowed, since they contain more than 10 chars.
Dealie
Member
165 Points
33 Posts
REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 11, 2005 06:15 PM|LINK
I look for any digit .*[0-9].* and for any character .*[a-zA-Z]+.* but I don't know how to connect them to search for at least one digit in any position and one character in any position (any appearance of)
Regards,
www.sdncenter.com
BobT
Member
725 Points
143 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 11, 2005 11:09 PM|LINK
This isn't easily done with 1 regex.
You need one regex to test for a letter and another to test for a digit.
If you say the password must start with a letter, then the regex is simple: @"^[A-Za-z]+\d+.*$"
In this dust that was a city
If I could find a souvenier
Just to prove the world was here
akchamarthy
Member
395 Points
86 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 12, 2005 12:25 AM|LINK
How about this...
^(?=.*\d)(?=.*[a-zA-Z]).{4,8}$
This will check for text string to have atleast one Numeric and one Character and the length of text string to be
between 4 to 8 characters.....Try this out...Njoy!
BobT
Member
725 Points
143 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 12, 2005 01:23 AM|LINK
I didn't realize that the RegEx engine did look ahead.
In this dust that was a city
If I could find a souvenier
Just to prove the world was here
Dealie
Member
165 Points
33 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 12, 2005 07:59 AM|LINK
That is great However unfortunatly it do not accept strings like "mypass1" because there is no letter after digit. it is accepting only "my1pass" or "1mypass".
What I need is to do exactly that what do your regex but without important order of appearance
Moreover (i don't know why) but it do not accept string where is more digits then characters like : "35463pas". But it is not a big problem...
Is it possible to make your regex that will ignore the order of appearance?
www.sdncenter.com
Dealie
Member
165 Points
33 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 12, 2005 08:09 AM|LINK
It was easy;) I googled your regex and I found some similar another versions of that I have combined them :) and I got exactly that what I need without important order of appearance :
Actual Regex is : ^.*(?=.{4,10})(?=.*\d)(?=.*[a-zA-Z]).*$
1) Search for at least one digit in any position
2) Search for at least one upper or lower case in any position
3) Enforce password to consist of 4-10 characters
Now it's exactly what I need;)
THANKS akchamarthy again:)!! I've just added ".*" twice and changed string leanght controlelr??(can it be called like that?) :)
Best Regards
www.sdncenter.com
akchamarthy
Member
395 Points
86 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 12, 2005 12:57 PM|LINK
bgs264
Participant
1083 Points
211 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Oct 02, 2008 03:10 PM|LINK
I know this is a nearly-3-year-old post so sorry to post a reply.
Just wanted to say thank you for posting this regular expression. I've spent most of today googling for it, and finally typed just the right thing into Google to find this page :)
I did modify it just slightly; because your regex would allow special characters and space characters. I wanted to validate a username with the rules 1. must be at least six characters; 2. must contain only letters or numbers; 3. must contain at least one letter.
To solve my problem, I adapted your regex slightly into:
^.*(?=.{6,})(?=.*[a-zA-Z])[a-zA-Z0-9]+$Thanks again!
wmoecke
Member
6 Points
3 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 20, 2010 10:28 AM|LINK
A huge THANX to both akchamarthy and Dealie for both your examples were exactly what I was looking for to come up with a quick win on a late friday evening issue - I know very little about RegEx, and needed to craft something out of thin air. Wouldn't be able to do it without these posts. Still good after 5 years!!
You guys are champs! I owe you a lot!
neff
Member
16 Points
12 Posts
Re: REGEX password must contain letters a-zA-Z and at least one digit 0-9
Sep 27, 2010 04:07 PM|LINK
Old thread, I know - I am looking at a very similar regex, and I'm almost there, but need some help finishing it off. Here's what I need:
1) 6-10 characters
2) At least one alpha AND one number
3) The following special chars are allowed (0 or more): !@#$%
Here's what I have:
^.*(?=.{6,10})(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z0-9!@#$%]+$
It works on all my test cases, except it allows "a1234567890", "testIt!0987", and "1abcdefghijk", none of which should be allowed, since they contain more than 10 chars.
Any ideas?