Forum Moderators: coopster
if (ereg('[^A-Za-z0-9]', $username))
{
// Continue the code.
}
else
{
trigger_error(U_INVALID_USERNAME);
} if (preg_match('/A-Za-z0-9/',$username)) if (preg_match('/A-Za-z0-9/',$username)) || (preg_match('/ /',$username)) || preg_match('/_/',$username)) /A-Za-z0-9/
// Matches one or more alphanumeric characters:
$pattern = '/[a-z0-9]+/i'; '/^[a-zA-Z0-9\_\&\s]+$/' however as long the name contains at least one uppercase/lowercase letter or number, other characters are allowed past the validation rule.
<?php
header("content-type:text/html");
$pwds= Array('ObNoxious','Pret3nti0us','and1MM@ture');
$errstring=$ok=null;
foreach ($pwds as $pwd) {
$pwd = preg_replace('/[^a-z\d]/i','',$pwd);
if (! (preg_match('/[a-z]/i',$pwd) and preg_match('/\d/',$pwd))) {
$errstring .= "<li>The password $pwd is an epic fail.</li>";
}
else { $ok .= "<li>$pwd is OK.</li>"; }
}
echo "<ul>$errstring $ok </ul>";
?>
$preg_str_check="#[^][ _A-Za-z0-9-]#";
if( preg_match( $preg_str_check, $some_input ) {
die("I'm not feeling helpful, so buzz off");
}
preg_match()will be
TRUE: