-1

How to add a condition where if the first character is 4 then 16 digits and if 3 then 15 digits?

this is what i tried so far:

<ion-input
            ngModel name="CNumber"
            required 
            (ionChange)="C_number($event.target.value)" 
            (ionInput)="C_number($event.target.value)"  
            maxlength="{{Maxlength}}"
            type="tel"
            pattern="^(4)[0-9]{15}$"
            >

^(4)[0-9]{15}

this will accept if the first is 4 and allows 16 characters, but how to add starting digit 3 and when so it accepts 15 characters only?

mrzasa
  • 22,895
  • 11
  • 56
  • 94
Omar .K
  • 73
  • 8

1 Answers1

0

I'd try simple.alternative:

^((4)[0-9]{15})|((3)[0-9]{14})$
mrzasa
  • 22,895
  • 11
  • 56
  • 94