Use the validateConstraint
validator:
<xp:inputText
id="inputText1"
value="..."
disableClientSideValidation="true">
<xp:this.validators>
<xp:validateConstraint message="Please enter only digits for phone number">
<xp:this.regex><![CDATA[^[0-9]*$]]></xp:this.regex>
</xp:validateConstraint>
</xp:this.validators>
</xp:inputText>
The regular expression ^[0-9]*$
accepts any number of digits and an empty string. If you want at least one digit then replace *
by +
.
You don't need to set the input text field as required.
You can decide where you'd like the validation message to appear. Set option disableClientSideValidation="false"
to show message as a dialog box on client side or disableClientSideValidation="true"
to put the message into xp:message/xp:messages control.