Hi,
I have a password reset form and a user can enter either there username or email in one text box.
One problem i am having is with validating the data.
I have a username regex function that works fine to validate username and uses php's inbuilt FILTER_VALIDATE_EMAIL.
Basically when a user submits form i want it to validate against the username regex OR php's filter_validate_email.
My validation code is this:
if (!preg_match(constant("USERNAME_REGEX"), $username_email) || !filter_var($username_email , FILTER_VALIDATE_EMAIL)) {
$error .= "Username/Email invalid format <br />";
}
Problem i am having is if i enter a valid email or valid username i still get the error shown in code above.
I am not sure what i can do. Can anyone suggest anything? I guess it's because i am asking PHP to validate it against two things that are conflicting with each other.
I wanted to validate it like this to avoid malicious submissions as i use regex validations throughout my site with other things like mysql_escape_string() etc.
I can only think of creating a regular expression combining the username pattern and a email pattern in one but i not got a clue about creating a regex pattern to validate an email.
My username regex is this:
// username regular expression
define('USERNAME_REGEX', '/^[a-z][\w\.\*\-\_]{2,14}$/i');
I know there are many email reg patterns online but don't know which ones are best and work as they should. Plus some are overly complex.
Thanks
PHPLOVER