ODeeKers,

Having a little trouble implementing a Regular Expression constraint.

The idea is that the answer to a question must be exactly 6 digits, no

more, no less.

123456 --YES

1234567 --NO

12345 --NO

I figure, a Regular Expression for 6 digits should look like this:

\d{6}

So, the Binding looks like this:

This works as it will not allow 5 digits, it will allow 6 digits, but

it will also allow MORE than 6 digits. 7 digits passes, I think,

because it is matching the first 6 digits and that is all that is

required. However, I also want to exclude anything larger than 6

digits.

What do you think?

thanks,

m0j0

I haven't tested this with javarosa, but in general I think this should work:

^\d{6}$

^ and $ are anchors for the beginning and end of text, respectively.

Best,

Adam

## ···

On Wed, Jun 16, 2010 at 6:17 PM, mojo wrote:
> ODeeKers,
>
> Having a little trouble implementing a Regular Expression constraint.
>
> The idea is that the answer to a question must be exactly 6 digits, no
> more, no less.
>
> 123456 --YES
>
> 1234567 --NO
>
> 12345 --NO
>
> I figure, a Regular Expression for 6 digits should look like this:
> \d{6}
>
> So, the Binding looks like this:
>
> required="true()" constraint="regex(., '\d{6}')" jr:constraintMsg="Le
> numéro de liaison doit avoir exactement 6 chiffres!" />
>
> This works as it will not allow 5 digits, it will allow 6 digits, but
> it will also allow MORE than 6 digits. 7 digits passes, I think,
> because it is matching the first 6 digits and that is all that is
> required. However, I also want to exclude anything larger than 6
> digits.
>
> What do you think?
>
> thanks,
>
> m0j0