This article contains different methods to validate an email address in PHP. It uses regular expressions and inbuilt email validation function. The input string is taken from the user and matches it with the predefined regular expressions and if the regular expression and input string found to be matched than it returns true and proceed further.
Method 1: Email validation using regular expression.
Valid email address.
Explanation: In the above example, passing the email to the user defined function email_validation( $email ), which use this example and matches with the regular expression by using the predefined function preg_match(). This predefined function match the whole input with regular expression and returns True if match found otherwise returns False.
Method 2: Email validation using filter_var() method.
email@example.com is a valid email address
Explanation: In the above example, passing the input email address to the predefined function filter_var(), which takes two parameters as input email and second is type of email filter. This function filters the email and returns true or false.
Method 3: Email validation using FILTER_SANITIZE_EMAIL filter.
author.gfg@GeeksforGeeks.com is a valid email address
Explanation: In the above example, use FILTER_SANITIZE_EMAIL filter to remove all unsupported characters and then use FILTER_VALIDATE_EMAIL filter to validate email.
- PHP | Send Attachment With Email
- Types of Email Attacks
- HTML | DOM Input Email Object
- Multi-threaded programming in Python
- Introduction of Graduate Record Examinations (GRE)
- egrep command in Linnux with examples
- How to select all child elements recursively using CSS?
- HTML | DOM Input Image Object
- HTML | DOM Ol start Property
- HTML | DOM Option disabled Property
- PHP | filter_has_var() function
- HTML | DOM KeyboardEvent keyCode Property
- HTML | DOM InputEvent
- HTML | DOM Parameter Object