QUIZGUM

Coding Class

Quizgum : Email Address Validation

Validate Email

Let's learn how to validate your email.
Use the filter_Var() built-in function.
And use the constant FILTER_VALIDATE_EMAIL as an argument.

How to validate email using filter_Var() function

  1. filter_Var('email address',FILTER_VALIDATE_EMAIL);

The first argument uses an email address and the second uses the constant FILTER_VALIDATE_EMAIL.
As shown in the example, you can change the purpose according to the value of a constant.
Returns true if the email address is valid or false.
The following example validates an email.

  1. <?php
  2. $email = "mybookforweb@gmail.com";
  3.  
  4. $checkMail = filter_Var($email, FILTER_VALIDATE_EMAIL);
  5.  
  6. if($checkMail == true) {
  7. echo "correct email";
  8. } else {
  9. echo "Your email address is not correct.";
  10. }
  11. ?>

the result of this code

  1. <?php
  2. $email = "mybookforweb@";
  3.  
  4. $checkMail = filter_Var($email, FILTER_VALIDATE_EMAIL);
  5.  
  6. if($checkMail == true) {
  7. echo "correct email";
  8. } else {
  9. echo "Your email address is not correct.";
  10. }
  11. ?>

the result of this code

You can use it to check if the email address you received when you registered is correct. ^^