In my application I have a field which have to store a phone number. The field must not allow characters but only numbers. The problem is that the format is something like:
0752344234
and if I add something like this, Xpages will save the field as: 752344234
without the 0.
Question: What method can I use to add the 0 in front of the numbers withouth using a string type field?
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.