Home  >  Article  >  Backend Development  >  新手提问

新手提问

WBOY
WBOYOriginal
2016-06-23 13:24:11893browse

声明一个字符串变量,为变量赋值。判断该字符串是否为邮箱格式。
这要用什么函数?感觉无从下手啊


回复讨论(解决方案)

如果要求很简单,检查是否包含@符号就可以了。如果要严格点就用正则来验证。

filter_var函数,功能很多,看下手册吧

var_dump(filter_var('abc@example.com', FILTER_VALIDATE_EMAIL));

<?php$str = 'abc@163.com';if(preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/",$str)){     echo '格式正确';}else{     echo '格式错误';}?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn