I am trying to create a user validation form to check the e-mail and also run it against my database. However, if there is an e-mail, such as "[email protected]", it will put it into the database anyway, even if it is a duplicate entry.
if (preg_match("/^([a-zA-Z0-9z])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {
//regular expression for email validation
$Email = $_POST['e-mail'];
} else {
$error[] = 'Your EMail Address is invalid ';
}
How would I change preg_match to look for the period in there? BTW, all users registering for the site will have a period in their e-mail (it is only for a select group of people that have the same e-mail format).
Your minimum goal is making sure that there's at least one period in the local part of the email address, because your specific use case requires this. We can probably bit a bit naive and use
/.*\..*@/
as the main check. This searches for zero or more of anything, one period, then zero or more of anything, then an at sign. This will successfully make sure that there's at least one dot in there, where it matters. Consider changing the *
s to +
s unless you want the string .@
to pass this check. I'm not sure where you expect the period, and can't remember off the top of my head whether or not periods are allowed as the first or last characters in the local part.
Combine this with a call to filter_var($_POST['e-mail'], FILTER_VALIDATE_EMAIL)
to actually check the full formatting of the address.