Jump to content

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


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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.