Regular expression (regex) for email validation

Regular expression (regex) for email validation

Regular expressions (regex) for email validation in some of the most common programming languages:


const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;


import re
emailRegex = re.compile(r'^[^\s@]+@[^\s@]+\.[^\s@]+$')


$emailRegex = '/^[^\s@]+@[^\s@]+\.[^\s@]+$/';


import java.util.regex.Pattern;
Pattern emailRegex = Pattern.compile("^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$");


using System.Text.RegularExpressions;
Regex emailRegex = new Regex(@"^[^\s@]+@[^\s@]+\.[^\s@]+$");

These regex patterns will match most valid email addresses and can be used in the respective programming languages for email validation. Note that there are many variations of email addresses that can be considered valid, and these patterns may not match all of them. Additionally, it's always important to consider additional validation methods, such as sending a confirmation email to the address provided, to ensure the email is valid and belongs to the user.