Hi,all
I want to ask for the php code to check the password validation?
It couldn't be entire alphabetic or entirely numeric?
Thanks.

Recommended Answers

All 6 Replies

Are you asking how to check for only numbers in a string? if so is_numeric would do this:

if (is_numeric($password)) {
        echo "Password is numeric";
     } else {
        echo "Password is not numeric";
   }

Or for alpha-numeric strings:

if (preg_match('/^[A-Za-z0-9]+$/', $password)) {
  // Do something
}
if (preg_match('/^[A-Za-z0-9]+$/', $password)) {
  // Do something
}

if i type password: pass123 should work
and i type password should not work correct??

here is a regex that will make sure the password has at least 1 uppercase letter, 1 lower case letter, and a number. which is a pretty secure password.

preg_match( "/^.*(?=.{3,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/",$password)

Thanks,kkeith29
Here is the code i wrote:

preg_match( "/^.*(?=.*{3,})(?=.*[a-z])(?=.*[A-Z]).*$/",$pass)

But get the warning:

Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 11 in password.php

Any idea about this??
Thanks.
Really new in php

preg_match( "/^.*(?=.{3,})(?=.*[a-z])(?=.*[A-Z]).*$/",$pass)

Try this!

no, actually this make my code die.
Which i want is really simple: password must more than 6 characters and should have one number and one alpha
Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.