3

Should be fairly straight forward. Trying to allow a forward slash in my numeric only ng-pattern for a form field (expiration date).

HTML:

              <input type="text" id="expiration-date" name="expirationDate"
                data-ng-model="register.expirationDate"
                data-ng-pattern="/^[0-9]+$/"
                data-ng-minlength="7"
                maxlength="7"
                placeholder="MM/YYYY"
                data-ui-mask="99/9999"
                data-ng-required="true">

Trying to allow the forward slash in the model, otherwise the model never updates because it only accept numbers. I have very little knowledge with regex.

Christopher Marshall
  • 10,678
  • 10
  • 55
  • 94

1 Answers1

6

Add a forward slash into the character class.

  <input type="text" id="expiration-date" name="expirationDate"
    data-ng-model="register.expirationDate"
    data-ng-pattern="/^[0-9\/]+$/"
    data-ng-minlength="7"
    maxlength="7"
    placeholder="MM/YYYY"
    data-ui-mask="99/9999"
    data-ng-required="true">
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274