Question

I created a number field on an xpage. However the input checking does not work properly. It accepts only numbers, which is expected behavour, but the number of entered digits is not validated. Numbers with more than 6 digits accepted which could not be possible, because of regExp \d{6}.

Here is the code on the xpage:

<xe:djNumberTextBox id="inputTextMidasId" dojoType="dijit.form.NumberTextBox" value="#{complaintDocument.midasId}" javaType="short" regExp="\d{6}"> <xe:this.constraints> <xe:djNumberConstraints pattern="######"> </xe:djNumberConstraints> </xe:this.constraints> </xe:djNumberTextBox>

Can anybody tell how to make this code working? Thank you.

Was it helpful?

Solution

I can not explain why the regular expression doesn't work as expected.

According to the XPages Extension Library book you can use the min and max properties of xe:djNumberConstraints to control minimum and maximum values allowed. So perhaps you should use those instead of the regular expression?

The following does exactly what you want:

<xe:djNumberTextBox id="djNumberTextBox1" value="#{viewScope.test}">
    <xe:this.constraints>
        <xe:djNumberConstraints min="1" max="999999"></xe:djNumberConstraints>
    </xe:this.constraints>
</xe:djNumberTextBox>

Update:

If you write 001 in a xe:djNumberTextBox it will be converted to 1 when the user leaves the field. Is this what you want?

With the xe:djValidationTextBox you can verify the input using a regular expression. The following will do your required verification, and will allow input such as 001 to be kept in the field:

<xe:djValidationTextBox id="djValidationTextBox1" regExp="\d{6}"></xe:djValidationTextBox>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top