source: Dev/branches/rest-dojo-ui/client/dojox/validate/us.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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