4

I want regex to validate Email Address, which rejects the email addresses like [email protected] or [email protected] or Raman [email protected].
It allow the emails which are containing at least one character or 'combination of number & characters' for example:- [email protected], [email protected], [email protected]

3
  • Write specific conditions for regex in your question. Commented Mar 18, 2020 at 10:35
  • so what kind of email format should be allowed? Please mention that in question. that will be helpful for specific question Commented Mar 18, 2020 at 10:57
  • Does this answer your question? How to validate an email address in JavaScript Commented Mar 18, 2020 at 11:20

1 Answer 1

5

The validation function I use:

function isEmail(email) {
    var emailFormat = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
    if (email !== '' && email.match(emailFormat)) { return true; }
    
    return false;
}

However, in your specific case, to further filter out cases like '[email protected]' and '[email protected]', the regexp shall be modified a bit into:

var emailFormat = /^[a-zA-Z0-9_.+]*[a-zA-Z][a-zA-Z0-9_.+]*@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;

or, more elegantly:

var emailFormat = /^[a-zA-Z0-9_.+]+(?<!^[0-9]*)@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;

Reference: Regex: only alphanumeric but not if this is pure numeric

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks brother, it's working
It's my pleasure!
Line 3 ff. can imho be simplified to return (!! email.match(emailFormat) (will be false on empty string, will return true resp. false on match/non-match)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.