regex: must have atleast 1 digit, how?

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
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

regex: must have atleast 1 digit, how?

Post by qads »

Code: Select all

<?php
if(!ereg("[a-zA-Z0-9]{5,15}", $password))
{
$form->error[] = 'Your password is invalid, password must be letters and numbers only, must have atleast 1 digit and should be 6 to 15 characters in length';
}
?>
the above, checks to see if the password is 6 to 15 chars in length, if it is numbers and letters, but how can i make it to check if it has atleast 1 digit in it? :? .

thanks
- Qads -
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

probably not want you want to hear .... but why not just ....

Code: Select all

if(! ( ereg("[a-zA-Z0-9]{5,15}", $password) && ereg("[0-9]+", $password) ) )
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

thats how i have it atm, just wanted to know, call it a learning thing :P.
Post Reply