Validate form for a required min/max integer value

Looking at Bastians form validation example, I try to include field that is required and only allows integer values that have a length of 11 chars. Here is what I tried in the rules array:

'number' => array('required', 'integer', 'min' => 10000000000, 'max' => 99999999999)

Unfortunately, this doesn’t work. What am I doing wrong?

Also, how am I able to use a specific regular expression by using this syntax?

Thanks a lot

How does it not work? Does it think valid numbers are invalid or does it not catch invalid numbers?

You can use the match option and pass a regular expression as the argument:

array('match' => '/something.*/')

Thanks for your quick reply.

It currently thinks all numbers are invalid.

I found a working solution for my form in the meantime:

'field' => array('required', 'match' => '/(?<!\d)\d{11}(?!\d)/')

This way only a value of 11 digits is valid.

Thanks for mentioning the match option.

Well, then the reason was that you use integer as validator. It actually checks if the value is an integer. But your value is most likely a number in a string.

Anyway, the RegEx solution is OK as well. You can even simplify it: /^\d{11}$/