0
VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)

HI Friends, I am using above email address expression to validate email. Problem I am geting is it is not allow ‍‍‍‍‍‍a@a.com emai‍l adddress for testing.

Any one please quide me what need to be change in expression.

Thanks you

Baba
  • 852
  • 1
  • 17
  • 31
DAVE
  • 31
  • 6
  • Relevant [SO thread](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – Stphane Apr 08 '14 at 12:56
  • Really, you should use a tokenizer and a state machine (or use a library that does it properly) if you're attempting to validate email addresses. They are *much* more complex than a simple regex can handle. – Phylogenesis Apr 08 '14 at 13:23

3 Answers3

1

You can try this function

function isValidEmailAddress(emailAddress) {
            var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
            return pattern.test(emailAddress);
        };

check the value as

if (!isValidEmailAddress(getEmailID)) {
}
Santhosh Kumar
  • 190
  • 3
  • 10
1

use this regexp

/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/

see this link: Email validation using jQuery

Community
  • 1
  • 1
Baba
  • 852
  • 1
  • 17
  • 31
1

you can use

/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
alvin
  • 28
  • 4