Validation rule for phone numbers

Hey guys,

I was wondering if anyone knew how to set a validation rule for phone number that only allowed numbers [0-9]. Our staff have a disturbing tendency to write notes in there.....

 

Do I add an assertion descriptor, namely assertion.number?

 

Cheers,

Matt

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Validation rule for phone numbers

You need to add a regularExpression assertion to the contact.phoneNumber archetype. e.g.:

<node name="telephoneNumber" path="/details/telephoneNumber"
      type="java.lang.String" minCardinality="0" maxLength="30">
    <assertion name="regularExpression">
        <property name="expression" value="^\d+$"/>
        <errorMessage>Invalid number</errorMessage>
    </assertion>
</node>

or:

<node name="telephoneNumber" path="/details/telephoneNumber"
      type="java.lang.String" minCardinality="0" maxLength="30">
    <assertion name="regularExpression">
        <property name="expression" value="^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$"/>
        <errorMessage>Invalid number</errorMessage>
    </assertion>
</node>

The first form only allows digits. The second is more flexible, but won't work for 13 and 18 numbers so you will need to experiment with it.

 

Re: Validation rule for phone numbers

Thanks heaps Tim.

That worked a treat!

I used the restrictive form (first). The "Name" field provides all the capacity for annotation we need.

Cheers,

matt

 

Syndicate content