Still needs a little refinement. The problem with both eregs here is that they aren't forced to match the entire string, but instead are content to match a single character anywhere within it.
Instead, use ^ and $ to anchor the pattern to the beginning and end of the string, and use + (non-empty closure) after the character class:
if (! ereg('[a-zA-Z0-9]+$',$password))
echo "bad password";
You can also use {} notation to specify specific length requirements, e.g. password must be between 6 and 20 chars:
if (! ereg('[a-zA-Z0-9]{6,20}$',$password))
This is quick and convenient; however it does have the disadvantage that it lumps all the possible failures together, so you can't issue separate informative messages such as 'letters and digits only', 'too short', etc.