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