比如用户输入[email protected]是可以的,但输入[email protected]就要提示格式错误。怎么用正则表达式写非“.”结尾的字符串?非常感谢
解决方案 »
- 请问PHP连接oracle8i,怎么配置
- apache配置,配置二级域名的问题
- php 镶入 htm文件能行吗?
- 请问饮用文件路径的问题
- httpd.conf 设置 charset的问题!
- 类内部的变量传递。高分求教,PHP高手请进。
- 请教大家一个问题
- mysql的host
- 两个类的概念问题:关于类中函数得的“默认值”及其他
- $$$给分请教:我把Linux上的一个网站下到win2000上,并且配置好了环境,但大量出现Warning: Failed opening '/home/www/include/global/c
- 请教高手 急需解决我这个困惑已久的问题 关于 httpd.exe的问题
- IIS和Apache能在Win2K3下面共同搭建吗?
你问的问题本身就存在问题了,非“.”结尾的字符串 : [email protected]这个是以com结尾吧。给你两个
$pattern='/^[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/';$pattern='/^[^@]*<[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?>$/';//两个,自己看着用哪个吧。
例如:
$patten = "/^\w+(?!=\.)$/is";
$wrongStr="[email protected]";$regex= '/\w[-.\w]*[^.]\@[-a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info)/';$matchCorrectStr = preg_match($regex, $correctStr);$matchWrongStr = preg_match($regex, $wrongStr);
echo "Result of match correct string:" .$matchCorrectStr;
echo "Result of match wrong string:" .$matchCorrectStr;结果:
Result of match correct string: 1
Result of match correct string: 0
解析:我们的这一个正则表达式可以拆分成三部分:
用户名 + @ + 主机名 1、用户名:/\w[-.\w]*[^.] 表示匹配除.结尾的任意ASCII字符
2、分隔符:\@ 匹配电子邮件的@分隔符
3、主机名:[-a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info) 点分的url主机地址可以包含数字字母或者-号
上面正则表达式摘抄自《精通正则表达式》 余晟 电子工业出版社出版