新手提问

WBOY
Release: 2016-06-23 13:24:11
Original
912 people have browsed it

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


回复讨论(解决方案)

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

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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template