validation - PHP: How to add more parameters to filter_var() to match also specific domains? -
i have html form email field want validate. i'm processing form php, used filter_var()
function.
the thing also want filter emails not contain 3 specific domains after @
sign (like email inserted should filtered if not legal, , if not @example.com
, @example2.com
or @example3.com
).
how may that?:
<?php if (!filter_var($_post['emailremitente'], filter_validate_email)) { echo "<br>oops! not valid email"; } else { ...
// array of domains rejected - domains must lower case $rejecteddomains = array('yahoo.com', 'hotmail.com', 'gmail.com'); // break email address (assuming have validated email already) $emailparts = explode('@',$_post['emailremitente']); // check if second element (the domain) in $rejecteddomains if (in_array(strtolower($emailparts[1]), $rejecteddomains)) { // rejected domain } else{ // accepted domain }
Comments
Post a Comment