Jump to content

I still don't get regex. Just want to check a simple one...


Jessica

Recommended Posts

I want to check that a string contains a letter and a number. I figured the simplest way for ME to do it is check it contains one letter, and then check if it contains a number, and if both are true, it's good.

 

I just still don't get regex.

 

<?
print preg_match('/[a-zA-Z]+[0-9]+/', $value);
?>

 

What am I doing wrong? I put "test1" as $value and still get 0?

Sorry, what it wasn't matching was: 1test.

 

This is the new expression that matches 1test and test1 and test1test so I think it will work. Can it be simplified any?

 

/([a-zA-Z])+([0-9])+|([0-9])+([a-zA-Z])+/

I recall that there is a way, but if you are doing password strength you want to let the user know what is missing, so why not just seperate them out into their own if statements, that way you know what is missing and can inform the user of it so they can properly fix it...

 

I have some code, but it is on a different PC at home, when I get home, if I remember, I will post my code for a password strength checker (it was made for AJAX).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.