使用eregi()帮助进行电子邮件地址验证 [英] Help with email address validation using eregi()

查看:89
本文介绍了使用eregi()帮助进行电子邮件地址验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




以下脚本取自John Coggeshall(PHP顾问)在Zends网站上的文章 http://www.zend.com/zend/spotlight/ev12apr.php


//获取要验证的电子邮件地址

$ email = $ _POST [''email'']

/ /使用John Coggeshalls脚本验证电子邮件地址

if(!eregi(" ^ [_ a-z0-9 - ] +(\。[_ a-z0-9 - ] +)* @ [a-z0-9 - ] +(\。[a-z0-9-

] +)*(\。[az] {2,3})$", $ email){

echo电子邮件无效;

}

else {

echo电子邮件是有效的;

}


在第一个例子中,如果我将脚本复制并粘贴到我的脚本中,脚本将不起作用

php文件。我得到一个解析错误信息。

在第二个例子中,有许多与脚本相关的帖子

有效性它仍然允许无效的电子邮件地址。

所以我有3个问题。

1)为什么我得到解析错误信息?

2)是否有确定的电子邮件验证脚本?

3)我在哪里可以找到正则表达式或其他表单验证脚本

验证电话号码,邮政编码等内容,不包含的名字

数字字符等等


亲切的问候

Dynamo

解决方案

email =


_POST [''email'']

//使用John Coggeshalls脚本验证电子邮件地址

if(!eregi(" ^ [_ a-z0-9 - ] +(\。[_ a-z0-9 - ] +)* @ [ a-z0-9 - ] +(\。[a-z0-9-

] +)*(\。[az] {2,3})


",

Hi

The following script was taken from John Coggeshall''s (PHP consultant) in his
article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php

// Get the email address to validate
$email = $_POST[''email'']
// Use John Coggeshalls script to validate the email address
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-
]+)*(\.[a-z]{2,3})$", $email) {
echo "The e-mail was not valid";
}
else {
echo "The e-mail was valid";
}

In the first instance the script does not work if I copy and paste it into my
php file. I get a parse error message.
In the second instance, there are many postings relating to the scripts
effectiveness in that it will still allow email addresses that are invalid.
So I have 3 questions.
1) Why do I get the parse error message?
2) Is there a definitive email validation script?
3) Where can I find regular expressions or other form validation scripts to
validate things such as telephone numbers, postcodes, names that don''t contain
numeric characters etc etc

Kind regards
Dynamo

解决方案

email =


_POST[''email'']
// Use John Coggeshalls script to validate the email address
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-
]+)*(\.[a-z]{2,3})


",


这篇关于使用eregi()帮助进行电子邮件地址验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆