email地址php检测
2006-06-06
作者:amao 同分类文章
description:
利用正则表达式 使用方法如下,具体函数请看详情
if (check_email_address($email)) {
echo $email . ' is a valid email address.';
} else {
echo $email . ' is not a valid email address.';
}
function check_email_address($email) {
// First, we check that there's one @ symbol, and that 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;
}
相关
MySQL两种表存储结构MyISAM和InnoDB的性能比较
关于取得上一条记录和下一条记录的问题!
Mysql 不能从远程连接的一个解决方法
MySQL数据的导出和导入工具:mysqldump
mysql text类型 长度不够的问题
zend studio 5.5 改为简体中文版的办法
PHP中文件格式类
无限级分类
IT业员工的流动很大的一个原因
用PHP和MySQL保存和输出图片