I have used below regex for email validation.
var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
How can i validate the below two email id like
- hello!%#%^world@gmail.com
- helloworld@-gmail.com
Vaild Email ids:
- hello-world@gmail.com
- hello.world@gmail.com
InVaild Email ids:
- hello!#%#@gmail.com
- helloworld@-gmail.com
Special characters should not be allow before @gmail.com
Below is my JavaScript code
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!re.test($(this).val())) {
errmsg.push($(this).attr('placeholder') + ' is invalid');
}