Validate Email Address In WordPress

Validate Email Address In WordPress

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
}

Newsletter

Subscribe to our newsletter to receive news and tutorials about WordPress and web development.

Meta Box - Create advanced WordPress custom fields and custom meta boxes with ease Download Now