Deluxe Blog Tips About Projects

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

Subscribe to the Newsletter

Subscribe to get my latest content by email. I won't send you spam. Unsubscribe at any time.