admin管理员组

文章数量:1426491

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.

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.

Share Improve this question asked Oct 13, 2014 at 19:08 Christopher MarshallChristopher Marshall 10.7k10 gold badges57 silver badges95 bronze badges 1
  • Explanation for the downvote? Or just mid day trolling? – Christopher Marshall Commented Oct 13, 2014 at 19:13
Add a ment  | 

1 Answer 1

Reset to default 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">

本文标签: javascriptAllow forward slash in ngpattern regexStack Overflow