Commit 2cf25e78ca66b3ad05c31b2f40e0ff758ecd8e13
1 parent
ec91b3b9
UI: Improve zip / postal code validation.
Showing
3 changed files
with
28 additions
and
5 deletions
... | ... | @@ -277,10 +277,33 @@ function Contact($compile, $templateCache) { |
277 | 277 | "Zimbabwe" |
278 | 278 | ]; |
279 | 279 | |
280 | + var postalCodePatterns = { | |
281 | + "United States": "(\\d{5}([\\-]\\d{4})?)", | |
282 | + "Australia": "[0-9]{4}", | |
283 | + "Austria": "[0-9]{4}", | |
284 | + "Belgium": "[0-9]{4}", | |
285 | + "Brazil": "[0-9]{5}[\\-]?[0-9]{3}", | |
286 | + "Canada": "[A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]", | |
287 | + "Denmark": "[0-9]{3,4}", | |
288 | + "Faroe Islands": "[0-9]{3,4}", | |
289 | + "Netherlands": "[1-9][0-9]{3}\\s?[a-zA-Z]{2}", | |
290 | + "Germany": "[0-9]{5}", | |
291 | + "Hungary": "[0-9]{4}", | |
292 | + "Italy": "[0-9]{5}", | |
293 | + "Japan": "\\d{3}-\\d{4}", | |
294 | + "Luxembourg": "(L\\s*(-|—|–))\\s*?[\\d]{4}", | |
295 | + "Poland": "[0-9]{2}\\-[0-9]{3}", | |
296 | + "Spain": "((0[1-9]|5[0-2])|[1-4][0-9])[0-9]{3}", | |
297 | + "Sweden": "\\d{3}\\s?\\d{2}", | |
298 | + "United Kingdom": "[A-Za-z]{1,2}[0-9Rr][0-9A-Za-z]? [0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}" | |
299 | + }; | |
300 | + | |
280 | 301 | var linker = function (scope, element) { |
281 | 302 | |
282 | 303 | scope.countries = countries; |
283 | 304 | |
305 | + scope.postalCodePatterns = postalCodePatterns; | |
306 | + | |
284 | 307 | var template = $templateCache.get(contactTemplate); |
285 | 308 | |
286 | 309 | element.html(template); | ... | ... |
... | ... | @@ -34,11 +34,11 @@ |
34 | 34 | </md-input-container> |
35 | 35 | <md-input-container class="md-block"> |
36 | 36 | <label translate>contact.postal-code</label> |
37 | - <input name="zip" ng-model="contact.zip" ng-pattern="/^([0-9]*)$/"> | |
37 | + <input name="zip" ng-model="contact.zip" ng-pattern="postalCodePatterns[contact.country]"> | |
38 | 38 | <div ng-messages="theForm.zip.$error" role="alert" multiple> |
39 | 39 | <div translate ng-message="pattern">contact.postal-code-invalid</div> |
40 | 40 | </div> |
41 | - </md-input-container> | |
41 | + </md-input-container> | |
42 | 42 | </div> |
43 | 43 | <md-input-container class="md-block"> |
44 | 44 | <label translate>contact.address</label> | ... | ... |
... | ... | @@ -294,9 +294,9 @@ export default angular.module('thingsboard.locale', []) |
294 | 294 | "contact": { |
295 | 295 | "country": "Country", |
296 | 296 | "city": "City", |
297 | - "state": "State", | |
298 | - "postal-code": "Postal code", | |
299 | - "postal-code-invalid": "Only digits are allowed.", | |
297 | + "state": "State / Province", | |
298 | + "postal-code": "Zip / Postal Code", | |
299 | + "postal-code-invalid": "Invalid Zip / Postal Code format.", | |
300 | 300 | "address": "Address", |
301 | 301 | "address2": "Address 2", |
302 | 302 | "phone": "Phone", | ... | ... |