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

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -