I’m trying to use validation in Spring.NET to validate that a string property of a class is a properly formatted e-mail address. I found the EmailValidator class (source, documentation), but I’m unsure of the syntax needed to actually use it with my class.
I’m trying this:
<v:email id="validate.myClass.MailFrom" test="MailFrom">
<v:message id="myClass.MailFrom" providers="myClassProvider"/>
</v:email>
but I get the error:
The element ‘group’ in namespace ‘http://www.springframework.net/validation’ has invalid child element ’email’ in namespace ‘http://www.springframework.net/validation’. List of possible elements expected: ‘validator, required, condition, regex, ref, collection, group, any, exclusive’ in namespace ‘http://www.springframework.net/validation’.
The same namespace that contains EmailValidator also contains ConditionValidator, RegularExpressionValidator, etc., which seem to correspond to allowed child elements. That doesn’t seem to be the case for EmailValidator. What am I missing?
Try something like
the email validator is a custom validator, which means you have to specify its type. In xml configuration, you use the validator tag as for your own custom validators. See http://www.springframework.net/doc-latest/reference/html/validation.html#d4e3643. I get your point about the other validator classes in the namespace having their own XML element. Maybe the email validator is considered too specific to warrant its own XML element?