When you register on a forum, there is usually an e-mail address verification function. when you enter an invalid format, an error message will appear. We can use the following rule expression ereg (^ [a-zA-Z0-9 _] @ [a-zA-Z0-9 \-] \. [a-zA-Z0-9 \-\.] $], $ email); however, the sub-function above can only check strings,
When you register on a forum, there is usually an e-mail address verification function. when you enter an invalid format, an error message will appear.
We can use the following rule expression
Ereg ("^ [a-zA-Z0-9 _] @ [a-zA-Z0-9 \-] \. [a-zA-Z0-9 \-\.] $]", $ email );
However, the sub-function above only checks strings and does not support output. We can further use this formula to achieve the function of returning information:
If (eregi ("^ [a-zA-Z0-9 _] @ [a-zA-Z0-9 \-] \. [a-zA-Z0-9 \-\.] $]", $ email ))
{
Return FALSE;
}
Next we can further check whether the host name exists:
List ($ Username, $ Domain) = split ("@", $ email );
If (getmxrr ($ Domain, $ MXHost ))
{
Return TRUE;
}
Else
{
If (fsockopen ($ Domain, 25, $ errno, $ errstr, 30 ))
{
Return TRUE;
}
Else
{
Return FALSE;
}
}
Now let's organize the above two functions with PHP to form a function:
Function checkEmail ($ email)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.