I want regex to validate Email Address, which rejects the email addresses like 123@gmail.com or abc-kumar@gmail.com or Raman kumar@gmail.com.
It allow the emails which are containing at least one character or 'combination of number & characters' for example:-
kumar123@gmail.com, abc564@xyz.com, kumar@outlook.com
Asked
Active
Viewed 631 times
2
Kumar
- 226
- 1
- 3
- 11
-
Write specific conditions for regex in your question. – Deep Kakkar Mar 18 '20 at 10:35
-
so what kind of email format should be allowed? Please mention that in question. that will be helpful for specific question – Deep Kakkar Mar 18 '20 at 10:57
-
Does this answer your question? [How to validate an email address in JavaScript](https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript) – Rashomon Mar 18 '20 at 11:20
1 Answers
1
I am just pasting the validation function I usually 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;
}
else{
return false;
}
}
However, in your specific case, to further filter out '123@gmail.com' and 'abc-kumar@gmail.com' (which are valid in my opinion by the way), the regexp shall be modified a bit to:
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
zhugen
- 146
- 7