Page 1 of 1

Contains a Digit

Posted: Wed Dec 21, 2005 9:09 pm
by Zoram
This is probably something really simple... but i can't seem to find anything on it.

Is there a way to tell if a string has digits in it?

I am trying to do password checks and make sure that the password has at least 1 digit.

Thanks!

Posted: Wed Dec 21, 2005 9:23 pm
by redmonkey
Off the top of my head I can't think of a function that will check that a string has a numeric character in it (I can only think of alphanumeric or strict numeric checks).

So, I'd prob just opt for a quick regex i.e...

Code: Select all

if (preg_match('/[0-9]+/', $string))
{
  // do something
}

Posted: Wed Dec 21, 2005 10:33 pm
by Zoram
That seems to have done the trick, thanks