Reputation: 9040
I have absolutely no idea about regex at all. I am trying to perform email validation in a PHP signup script (to check if a valid email has been entered). I have got a script from the internet but I don't know how it works and I am completely unfamiliar with the functions used. I found out that the function they used (eregi_replace()
) is deprecated in favor of preg_replace()
. Firstly, can someone guide me through the steps of the function below, and secondly can you explain the preg_replace()
function and how it works?
The validation script:
$regex = "([a-z0-9_.-]+)". # name
"@". # at
"([a-z0-9.-]+){2,255}". # domain & possibly subdomains
".". # period
"([a-z]+){2,10}"; # domain extension
$eregi = eregi_replace($regex, '', $email);
$valid_email = empty($eregi) ? true : false;
The script was sourced from here
Upvotes: 0
Views: 47
Reputation: 89639
regex are not needed here:
filter_var('[email protected]', FILTER_VALIDATE_EMAIL);
if you want training i suggest you to visit http://www.regular-expressions.info and http://php.net
To quickly test a pattern you can use this online tool: http://regex.larsolavtorvik.com/
Upvotes: 4