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]
-
Write specific conditions for regex in your question.Deep Kakkar– Deep Kakkar2020-03-18 10:35:42 +00:00Commented 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 questionDeep Kakkar– Deep Kakkar2020-03-18 10:57:52 +00:00Commented Mar 18, 2020 at 10:57
-
Does this answer your question? How to validate an email address in JavaScriptRashomon– Rashomon2020-03-18 11:20:26 +00:00Commented Mar 18, 2020 at 11:20
Add a comment
|
1 Answer
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