summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/validate/ca.js
blob: 498304ca2d28a82ea7950a1ded086418b24a21a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//>>built
define("dojox/validate/ca", ["dojo/_base/lang", "./_base", "./regexp", "./us"], 
 function(lang, validate, xregexp, us){
/*=====

	dojox.validate.ca = {
		// summary: Module which includes Canadian-specific methods for dojox.validate
	}

=====*/

var ca = lang.getObject("ca", true, validate);
lang.mixin(ca, {
	
	isPhoneNumber: function(/* String */value){
		// summary: Validates Canadian 10-digit phone number for several common formats
		return us.isPhoneNumber(value);  // Boolean
	},

	isProvince: function(/* String[2] */value) {
		// summary: Validates Canadian province abbreviations (2 characters)
		var re = new RegExp("^" + xregexp.ca.province() + "$", "i");
		return re.test(value); // Boolean
	},
 
	isSocialInsuranceNumber: function(/* String */value) {
		// summary: Validates Canadian 9 digit social insurance number for several
		//		common formats
		//
		// description:
		//		Validates Canadian 9 digit social insurance number for several
		//		common formats. This routine only pattern matches and does not
		//		use the Luhn Algorithm to validate number.
		//
		var flags = { format: [ "###-###-###", "### ### ###", "#########" ]};
		return validate.isNumberFormat(value, flags); // Boolean
	},

	isPostalCode: function(value) {
		// summary: Validates Canadian 6 digit postal code
		//
		// description:
		//		Validates Canadian 6 digit postal code.
		//		Canadian postal codes are in the format ANA NAN,
		//		where A is a letter and N is a digit, with a space
		//		separating the third and fourth characters.
		//
		var re = new RegExp("^" + xregexp.ca.postalCode() + "$", "i");
		return re.test(value); // Boolean
	}

});

return ca;
});