preg_match_all("/[^A-Za-z0-9]/",$new_password,$out);
The above only checks the 1st character, how to check whether all are alpha-numeric?
preg_match_all("/[^A-Za-z0-9]/",$new_password,$out);
The above only checks the 1st character, how to check whether all are alpha-numeric?
preg_match("/^[A-Za-z0-9]*$/", $new_password);
This gives true if all characters are alphanumeric (but beware of non-english characters). ^ marks the start of the string, and ^$^ marks the end. It also gives true if the string is empty. If you require that the string not be empty, you can use the + quantifier instead of *:
preg_match("/^[A-Za-z0-9]+$/", $new_password);
It's probably a better idea to use the builtin functions: ctype_alnum