javascript - What is the regular expression for zip code i.e. 96754-2222 -
<input class="input-width" placeholder="xxxxx" maxlength="10" type="text" name="zip" ng-model="shipping.zip" required ng-pattern="/^[0-9]+$/" /> this entering numbers.how enter 5 numbers '-' 4 numbers. new regular expressions. can me in create one.
this matches requirements:
^[0-9]{5}(?:-[0-9]{4})?$ that is:
characters 0-9 | 5 of them | | v v ^[0-9]{5}(?:-[0-9]{4})?$ ^^^ ^ | | | group optional | group (no-capture) see annotations. there literal - dash , ^ , $ anchor @ beginning , end of string.
5 digits followed optional - , 4 digits.
Comments
Post a Comment