How to allow numbers only with f: validateRegex

I have an input that should only allow numbers. I tried adding <f:validateRegex> as follows:

 <f:validateRegex pattern="[0-9]" /> 

But I still get the error message,

Validation error: value does not match pattern '[0-9]'

How is this caused and how can I solve it?

+6
source share
1 answer

The pattern [0-9] allows you to enter only a single digit. Perhaps you need to enter a few digits? In this case, you should use the template [0-9]+ . Modifier + means "one or more."

 <f:validateRegex pattern="[0-9]+" /> 

If you allow empty input, use the * modifier instead, which means "zero or more."

 <f:validateRegex pattern="[0-9]*" /> 

See also:

+14
source

All Articles