Here’s the code I’m using:
if (filter_var($desired_username, FILTER_VALIDATE_EMAIL) || ((strlen($desired_username)) > 32)) {
$usernamevalidate=FALSE;
} else {
$usernamevalidate=TRUE;
}
strlen is working perfectly, but either filter_var or FILTER_VALIDATE_EMAIL is not. Don’t let the variable name trick you, “$desired_username” links to a field for an email, but it’s just not working.
I can enter “test” instead of “test@test.com” or even “test@test” and it still validates. I’ve also tried preg_match and other methods, but none of them are validating properly.
Any help would be appreciated.
Several things:
filter_varworks backwards. A valid e-mail is going to set$usernamevalidate=FALSEwith your code.You should be doing this instead: