[483] | 1 | define(["dojo/_base/lang", "./_base", "./regexp"], |
---|
| 2 | function(lang, validate, xregexp){ |
---|
| 3 | |
---|
| 4 | var us = lang.getObject("us", true, validate); |
---|
| 5 | us.isState = function(value, flags){ |
---|
| 6 | // summary: |
---|
| 7 | // Validates US state and territory abbreviations. |
---|
| 8 | // value: String |
---|
| 9 | // A two character string |
---|
| 10 | // flags: Object? |
---|
| 11 | // - flags.allowTerritories Allow Guam, Puerto Rico, etc. Default is true. |
---|
| 12 | // - flags.allowMilitary Allow military 'states', e.g. Armed Forces Europe (AE). Default is true. |
---|
| 13 | |
---|
| 14 | var re = new RegExp("^" + xregexp.us.state(flags) + "$", "i"); |
---|
| 15 | return re.test(value); // Boolean |
---|
| 16 | }; |
---|
| 17 | |
---|
| 18 | us.isPhoneNumber = function(/*String*/value){ |
---|
| 19 | // summary: |
---|
| 20 | // Validates 10 US digit phone number for several common formats |
---|
| 21 | // value: |
---|
| 22 | // The telephone number string |
---|
| 23 | |
---|
| 24 | var flags = { |
---|
| 25 | format: [ |
---|
| 26 | "###-###-####", |
---|
| 27 | "(###) ###-####", |
---|
| 28 | "(###) ### ####", |
---|
| 29 | "###.###.####", |
---|
| 30 | "###/###-####", |
---|
| 31 | "### ### ####", |
---|
| 32 | "###-###-#### x#???", |
---|
| 33 | "(###) ###-#### x#???", |
---|
| 34 | "(###) ### #### x#???", |
---|
| 35 | "###.###.#### x#???", |
---|
| 36 | "###/###-#### x#???", |
---|
| 37 | "### ### #### x#???", |
---|
| 38 | "##########" |
---|
| 39 | ] |
---|
| 40 | }; |
---|
| 41 | return validate.isNumberFormat(value, flags); // Boolean |
---|
| 42 | }; |
---|
| 43 | |
---|
| 44 | us.isSocialSecurityNumber = function(/*String*/value){ |
---|
| 45 | // summary: |
---|
| 46 | // Validates social security number |
---|
| 47 | var flags = { |
---|
| 48 | format: [ |
---|
| 49 | "###-##-####", |
---|
| 50 | "### ## ####", |
---|
| 51 | "#########" |
---|
| 52 | ] |
---|
| 53 | }; |
---|
| 54 | return validate.isNumberFormat(value, flags); // Boolean |
---|
| 55 | }; |
---|
| 56 | |
---|
| 57 | us.isZipCode = function(/*String*/value){ |
---|
| 58 | // summary: |
---|
| 59 | // Validates U.S. zip-code |
---|
| 60 | var flags = { |
---|
| 61 | format: [ |
---|
| 62 | "#####-####", |
---|
| 63 | "##### ####", |
---|
| 64 | "#########", |
---|
| 65 | "#####" |
---|
| 66 | ] |
---|
| 67 | }; |
---|
| 68 | return validate.isNumberFormat(value, flags); // Boolean |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | return us; |
---|
| 72 | }); |
---|