A validated email function written by a cow.

Source: Internet
Author: User
Tags ereg explode return domain domain name to domain
Function

From Haohappy ' S blog an email validation function

<?php
function Valid_email ($email) {
We check that there ' s one @ symbol, and that's the lengths are right
if (!ereg ("^[^@]{1,64}@[^@]{1,255}$", $email)) {
Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
Split it into sections to make life easier
$email _array = explode ("@", $email);
$local _array = Explode (".", $email _array[0]);
for ($i = 0; $i < sizeof ($local _array); $i + +) {
if (!ereg ("^" ([a-za-z0-9!#$%& ' *+/=?^_ ' {|} ~-][a-za-z0-9!#$%& ' *+/=?^_ ' {|} ~\.-]{0,63}) | (\ "[^ (\\|\")]{0,62}\)) $ ", $local _array[$i])) {
return false;
}
}
if (!ereg ("^\[?[ 0-9\.] +\]?$ ", $email _array[1])) {//Check if domain is IP. If not, it should be valid domain name
$domain _array = Explode (".", $email _array[1]);
if (sizeof ($domain _array) < 2) {
return false; Not enough parts to domain
}
for ($i = 0; $i < sizeof ($domain _array); $i + +) {
if (!ereg ("^" ([a-za-z0-9][a-za-z0-9-]{0,61}[a-za-z0-9]) | ( [a-za-z0-9]+)) $ ", $domain _array[$i])) {
return false;
}
}
}
return true;
}
?>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.