Hi Carl, I'm afraid the code that actually /calls/ the validator, is stripping the square brackets, so you can't pass in the regexp you mentioned below. I haven't looked up the code that calls a validator, but I assume it has to do with the syntax of the ognl-_expression_-parsing. The parser is using square brackets to set the boundaries of the total _expression_, so you can't pass those in. On another thread, I more or less asked the same question, but did not get a reply. This caused me to write my own validator, that /does/ accept square brackets. Well, sort of. It replaces all accolades ( "{" and "}" ) by square brackets. This allows me to use, for example: <binding name="validators" value="validators:mzzPattern={a-zA-Z}*"/> <!-- This will be replaced by: [a-zA-Z] --> or, including a custom error message: <binding name="validators" value="validators:mzzPattern={^%}.*[{0} may not start with a '%'.]"/> <!-- This will be replaced by: [^%].* --> The code for the validator I wrote is fairly straightforward: public class PatternValidator extends BaseValidator { private static final Log log = LogFactory.getLog(PatternValidator.class); private String pattern; public void setMzzPattern(String pattern) { this.pattern = pattern.replace('{','[').replace('}',']'); } public void validate(IFormComponent field, ValidationMessages messages, Object object) throws ValidatorException { if( log.isDebugEnabled() ) { log.debug("Validating input: "+object+" pattern:"+pattern); } if( object==null ) { return; } if( !Pattern.matches(pattern,object.toString())) { if( messageKey==null ) { setMessageKey("{0} dos not comply to regExp: "+pattern); } throw new ValidatorException(buildMessage(messages, field), ValidationConstraint.PATTERN_MISMATCH); } } } Hope this helps. Anybody with a better way? Would love to see that too. Martijn BTW: you can find the code of Tapestry's pattern validator at: tapestry-4.0.1\framework\src\java\org\apache\tapestry\form\validator\Pattern.java Carl Pelletier wrote: Hi everyone, I'm trying to validate a Canadian Postal code in a text field. Can somebody point me to the doc where I can find all the type of pattern supported by pattern= in the validator ?I search on the forum and get a look at the online doc, but can't find explication on this. For now, I'm trying to do something like: <input class="postalCode" maxlength="8" jwcid="[EMAIL PROTECTED]" type="text" value="ognl:address.postalCode" validators="validators:pattern=[A-Z][0-9][A-Z][SPACE][0-9][0-9][A-Z][0-9][%postalCode-format]" displayName="postalCode" /> Thanks for any help ! sorry for the bad english... P.S. I'm thinking of starting a french version of this forum. Please email me if your think it's a good idea. Carl Pelletier --
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Cumquat Information Technology De Dreef 19 3706 BR Zeist T +31 (0)30 - 6940490 F +31 (0)10 - 6940499 http://www.cumquat.nl [EMAIL PROTECTED] M +31 6 22 384 318 |