manu
manu

Reputation: 351

Laravel minimum length validation for numbers not working

Laravel minimum length validation for numbers not working, please find the following expressions

  'country_code' => 'regex:/^.{2,4}$/',
  'country_code' => 'bail|required|numeric',

i need to restrict 1 digit nubers including zero ex: (01,+1,00,99,999,......) are valid (0,+,1,......) are invalid

Upvotes: 0

Views: 539

Answers (2)

The fourth bird
The fourth bird

Reputation: 163217

If the maximum number you want to match is 999, you might use an alternation to match either a plus followed by matching 1-3 digits or match 2-3 digits.

^(?:\+\d{1,3}|\d{2,3})$

Regex demo

Upvotes: 1

Jignesh Joisar
Jignesh Joisar

Reputation: 15095

to allow 01 in your case try

^(?:[0-9][0-9]{1,3}|[0-9])$ 

see

Upvotes: 0

Related Questions