On 11 avr. 2012, at 12:03, Hardy Ferentschik wrote: >> >> If we go back to our example, @Email(regexp=""^((?!\\.org).)*$") is not >> really 5 nor even 2 times better than @Email >> @Pattern((regexp=""^((?!\\.org).)*$") > > I am not sure how one would measure this leverage factor so I stay out of it. > Adding the regexp is backwards compatible, its optional and hence for most > users > not visible. If you are going to need it you have the choice between: > > @Email(regexp=""^((?!\\.org).)*$") > > or > > @Email > @Pattern((regexp=""^((?!\\.org).)*$") > > I don't see any harm here. In fact I think that the first version even adds a > little more context information, because it tells me that the main concern is > about making sure > that we have an email (meeting an additional validation criteria). In the > second case the @Pattern could also be just replacing a @NotEmpty (depending > on the > regular expression of course) constraint.
To me, it adds complexity : - in HV's code but that's not a strong factor in this case - more doc - as a user looking at @Email when I use it, I have to understand why such an option has been added and if I need it And I don't see why you don't add regexp to CreditCardNumber, ModCheck, NotBlank, NotEmpty and SafeHtml. There are "equally valid" use cases for that. But if you add them to all these annotations, I will start to question your massive duplication error. > >> And frankly, regexp is about the less readable construct in the history of >> programming languages. > > and one of the most powerful one as well :-) Sure but we have @Pattern for that already :) > >> I am not against some functional flags to >> restrict the domain, ensure that it's an email address reachable from the >> internet etc etc > > I am not against additional flags either, and I was in fact thinking whether > a "reachable" flag to @Email and @URL would make sense. This is something > which is outside > the character based validation. Regarding the domain restriction flag, where > do you draw the line? Do you want a includeDomain, excludeDomain, > includeUser, excludeUser, allowGmail, disallowYahoo, … - or do you rather add > a regexp flag? That's the thing, you have to draw a line in the sand and find the top n use cases you think an annotation can deal with without becoming a Christmas tree. Thinking about it, I think it would make sense to offer a setting to enforce the email does not address the local network but is globally accessible. About domain restriction, I'm thinking that invalid address != not from the expected domain and a separate constraint makes more sense. _______________________________________________ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev