PDA

View Full Version : User Name preg_match not working.


songboy
06-03-2010, 06:15 PM
Sorry, it's the old nutshell again.
My password must have 10 alphanumerics and there must be one capital, one lower case and one digit. I found the following and it's not working. Would someone let me know why ?

if(!preg_match("/^(?=\w{10})(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])$/",$user_name))

I've tried variations of the above but none clear the error message.

Thanks -
Songboy

davidj
06-04-2010, 11:14 AM
regex was created by the devil himself

I'll have a look later and report back

I need to be in a Jazz Trance

edbr
06-07-2010, 05:59 AM
http://gskinner.com/RegExr/ (http://www.php-developer.org/testpregmatch.php)

have a look here

songboy
06-07-2010, 10:55 PM
OK dj, edbr and other observers, I think I've cracked it. This:

if(!preg_match("/^.*(?=.{10})(?=\d*[A-Za-z])(?=\w*[0-9]).*$/"

seems to work for any variation of ten alphanumerics. For example:
Q1asdfghjk or Qasdfghjk1 or asdfghjk1Q or asdfQ1ghjk etc etc.
The thing that initially sent me on the wrong trail was a commentary referring to the initial .* I'd seen this but thought it was a look ahead linked to something like {10,} so I left it out because I only wanted ten characters. I think the .* at the end must be a look back but I'm not sure.
Linking these [A-Za-z] into one bracket was just fluke - I'm not clear why this works and the other one doesn't.
Anyway, the next one is a passkey which must have four digits and four lowercase letters - should be a doddle !
All the best -
Songboy