0

I have to validate the brazil phone no, in brazil phone can be started with zero and it will be 8 digits I have given <input type="number" name="mobileNo" ng-model="booking.phone" ng-pattern="/^[0-9]{8,8}$/" required placeholder="Phone no">

validation is working fine if i given something like "25869859" But if i have given as "02587895" it is not counting the first number if it is start with zero, it is taking 9 digits what is need is it should take only 8 digits even if i given number starting with zero

Gollapalli
  • 20
  • 3

1 Answers1

1

Try change the Quantifier: ^[0-9]{8,9}$

Quantifier - {8,9} Matches between 8 and 9 times

Or if you want to verify 0, try:

 ^0?[0-9]{8,8}$

0? matches the character 0 literally between zero and one times, as many times as possible, giving back as needed


Demo

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225