avatar 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

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com