Validate Email Address In WordPress

3656609003 3de1bfcca8 t Validate Email Address In WordPressValidate email address is very common task for all web developers. An usual method is using regular expression. This is strong method and works in most cases. But in WordPress, we don’t have to spend plenty of time thinking about validation pattern. WordPress has some built-in functions for this problem. Here’s the code:

if (empty($email) || !is_email($email)) {
    // display error
} else {
    // successful
}

If you want to check email address is in the database or not, use this function:

if (email_exists($email)) {
    // email is in the database
} else {
    // email is not in the database
}

Leave a Reply