Contains a Digit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Contains a Digit

Post 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!
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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
}
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

That seems to have done the trick, thanks
Post Reply