How to implement simple email address verification on the same page? Solution-php Tutorial

Source: Internet
Author: User
How to implement simple email address verification on the same page? I am a newbie. I recently learned the php filter chapter and want to enter an email address on the same page, click submit to verify whether the input is valid. the code is as follows. This code cannot implement this function: & lt; html & gt; & lt; body & gt; & lt; title & gt; email-test & lt; title & gt; & how to implement simple email address verification on the same page?
I am a Cainiao. I recently studied the php filter Chapter. I want to enter an email address and click submit on the same page to verify whether the input has been completed and the input is valid, the code is as follows. This code cannot implement this function:



Email-test
//
Email-addr:




Function emailtest ($ email)
{
If (filter_has_var (INPUT_GET, "email "))
{

Echo ("Input type does not exist ");
}
Else
{
If (filter_input (INPUT_GET, "email", FILTER_VALIDATE_EMAIL ))
{
Echo "E-Mail is not valid ";
}
Else
{
Echo "E-Mail is valid ";
}
}
}
?>




------ Solution --------------------
... What do I mean? Filter_input (): if the verification fails, false is returned.
If (filter_input (INPUT_GET, "email", FILTER_VALIDATE_EMAIL ))
{
Echo "E-Mail is not valid ";
}
If the variable is valid, the returned result is not valid.
Discussion

Reference:

You just reversed the logic.


Nun? Please advise. I feel more and more logic and often get confused.

------ Solution --------------------
Function validateEmail ($ email ){
Return preg_replace ("/^ [a-zA-Z0-9] + [a-zA-Z0-9 _-] + @ [a-zA-Z0-9] + [a-zA-Z0-9. -] + [a-zA-Z0-9] +. [a-z] {2, 4} $/", $ email );
}

If (! ValidateEmail ($ _ POST ['email ']) {
Echo" Invalid E-mail:Type a valid e-mail please .";
}
Hope to help you

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.