Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow numbers only using f:validateRegex

I've an input which should allow numbers only. I tried adding <f:validateRegex> as follows:

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

But I still get the error message,

Validation Error: Value not according to pattern '[0-9]'

How is this caused and how can I solve it?

like image 565
Erfan Avatar asked Oct 22 '12 14:10

Erfan


1 Answers

The pattern [0-9] allows input of a single digit only. Perhaps you want input of multiple digits? In that case, you should use a pattern of [0-9]+. The + modifier namely means "one or more".

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

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

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

See also:

  • regular-expressions.info - the premier website about regular expressions
like image 129
BalusC Avatar answered Oct 22 '22 04:10

BalusC