1

I am using tapestry 4 on my web application. I have tapestry validating my email address field. According to the tapestry documentation it uses regex to validate the email addresses

^\w[-._\w]*\w@\w[-._\w]*\w\.\w2,6$

But when I enter an email address that ends with .cat or anything similar the validation catches an error and it will not save the email address.

Does anyone know why this is happening as I am not familiar with regex?

flexinIT
  • 431
  • 2
  • 10
  • 28
  • 1
    This seems to be a bug: it looks like it will only accept "existing" TLDs, regardless of the fact that the email is valid according to RFC 5322. `a@b` is also valid and this will fail their regex, by the way. – fge Jan 11 '13 at 10:52
  • just out of curiosity, do you know what addresses this will allow? or is it just com, info, net and org, and country code top-level domains? – flexinIT Jan 11 '13 at 10:56
  • 1
    I guess you can use a normal email regex http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address – Oscar Castiblanco Jan 11 '13 at 10:58
  • 1
    @flexinIT I have no idea. I'd recommend using the javax.mail api and use `new InternetAddress(theString, true) to validate in any case. Regexes for emails are just no good. – fge Jan 11 '13 at 10:59
  • @fge: thanks for you help, i will give javax.mail a go and see how that works out... thanks :) – flexinIT Jan 11 '13 at 11:01
  • 1
    If .com email domains work, but .cat doesn't then that's an issue with validator that's used after this regex, because this regex doesn't differentiate between .cat and .com – RokL Jan 11 '13 at 12:28

1 Answers1

2

I think the documentation you have mentioned might have some issue with that example.

The correct version of that regexp should be (not far away from the given one)

^\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,6}$

Last section (\w{2,6}) matches top domain which (according to that regular expression) should be from 2 to 6 characters.

Have a look at this page regex101 website. It's extreamly handy to experiment with your regexp

Tom
  • 26,212
  • 21
  • 100
  • 111