-1

i have following regular expression but it's not working properly it takes only three values after @ sign but i want it to be any number length

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

this@thi This is validated this@this It is not validating this expression

Can you please tell me what's the problem with the expression... Thanks

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
girish
  • 701
  • 3
  • 12
  • 22
  • If this is for email, check out this perl regex, which caters to rfc822: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html –  Jun 08 '10 at 04:52
  • possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – tripleee May 02 '15 at 08:15

2 Answers2

0

If you want your regex to match "any number length" then why are you using {2,4}?

I think a better example of the strings you're trying to match might give others a better idea of what you want, because based on your regex it is a bit confusing what you're looking for.

sholsapp
  • 15,542
  • 10
  • 50
  • 67
0

Try this:

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

The main problem is that you didn't escape the dot: \.. In regular expression the dot matches everything (mostly), making your regex quite liberal.

Kobi
  • 135,331
  • 41
  • 252
  • 292