-4

Possible Duplicate:
What is the best regular expression for validating email addresses?

I want email validator with specific domains where for example:

asdf@asdf.asdf invalid
test@test.co.in  valid
test@test.com  valid
test@test..com   invalid
test.@.test.com   invalid

So If i specify "asdf" in my regex expression then it can also be validated.

Community
  • 1
  • 1
k-s
  • 2,192
  • 11
  • 39
  • 73

1 Answers1

0

Try below one

\w+@\w+(\.[a-z]{1,3})+$

Below is the change as requested.

\w+@\w+.(biz|com|au)$
Pankaj
  • 9,749
  • 32
  • 139
  • 283
  • Ya. You are right. Corrected the answer now. Thank You. – Pankaj Jan 19 '12 at 12:07
  • But what if I want to allow "asdf" as domain name. – k-s Jan 19 '12 at 12:09
  • like:: I want to allow only email address which ends with test@test.com, test@test.biz, test@test.co.au -- but in future If i add another domain at end like "co.in" then it should allow. – k-s Jan 19 '12 at 12:15
  • Something REGEX like ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$ but it is not working to me.. – k-s Jan 19 '12 at 12:15
  • Do you want to validate for .com .biz .au only ?? – Pankaj Jan 19 '12 at 12:16
  • yes for now I want to allow for limited domains. But as per changes in regex I can add more domain in regex to validate in future. – k-s Jan 19 '12 at 12:18