Dashboard > WebWork > ... > Cookbook > How to validate field formats, such as a phone number
  WebWork Log In View a printable version of the current page.  
  How to validate field formats, such as a phone number
Added by James House, last edited by tm_jee on Aug 15, 2007  (view change)
Labels: 
(None)

Validating the format of String fields for patterns (such as a phone number) is easy with StringRegexValidator (named "regex" in the default validator configuration).

Simply add the validator the field in question, and supply a regular expression to match it against.


<validators>
    <field name="phone">
        <field-validator type="regex">
            <param name="expression">\([\d][\d][\d]\) [\d][\d][\d]-[\d][\d][\d][\d]</param>
            <message>Phone number must be in the format (XXX) XXX-XXXX</message>
        </field-validator>
    </field>
</validators>


If your expression tests against alpha characters, you may be interested in the "caseSensitive" parameter of with Validator as well. It defaults to "true".

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators