Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.validate.creditCard");
13
dojo.provide("dojo.validate.creditCard");
12
dojo.require("dojo.lang.common");
14
dojo.require("dojo.lang.common");
13
dojo.require("dojo.validate.common");
15
dojo.require("dojo.validate.common");
14
dojo.validate.isValidCreditCard = function (value, ccType) {
16
dojo.validate.isValidCreditCard = function (value, ccType) {
15
	if (value && ccType && ((ccType.toLowerCase() == "er" || dojo.validate.isValidLuhn(value)) && (dojo.validate.isValidCreditCardNumber(value, ccType.toLowerCase())))) {
17
	if (value && ccType && ((ccType.toLowerCase() == "er" || dojo.validate.isValidLuhn(value)) && (dojo.validate.isValidCreditCardNumber(value, ccType.toLowerCase())))) {
16
		return true;
18
		return true;
17
	}
19
	}
18
	return false;
20
	return false;
19
};
21
};
20
dojo.validate.isValidCreditCardNumber = function (value, ccType) {
22
dojo.validate.isValidCreditCardNumber = function (value, ccType) {
21
	if (typeof value != "string") {
23
	if (typeof value != "string") {
22
		value = String(value);
24
		value = String(value);
23
	}
25
	}
24
	value = value.replace(/[- ]/g, "");
26
	value = value.replace(/[- ]/g, "");
25
	var results = [];
27
	var results = [];
26
	var cardinfo = {"mc":"5[1-5][0-9]{14}", "ec":"5[1-5][0-9]{14}", "vi":"4([0-9]{12}|[0-9]{15})", "ax":"3[47][0-9]{13}", "dc":"3(0[0-5][0-9]{11}|[68][0-9]{12})", "bl":"3(0[0-5][0-9]{11}|[68][0-9]{12})", "di":"6011[0-9]{12}", "jcb":"(3[0-9]{15}|(2131|1800)[0-9]{11})", "er":"2(014|149)[0-9]{11}"};
28
	var cardinfo = {"mc":"5[1-5][0-9]{14}", "ec":"5[1-5][0-9]{14}", "vi":"4([0-9]{12}|[0-9]{15})", "ax":"3[47][0-9]{13}", "dc":"3(0[0-5][0-9]{11}|[68][0-9]{12})", "bl":"3(0[0-5][0-9]{11}|[68][0-9]{12})", "di":"6011[0-9]{12}", "jcb":"(3[0-9]{15}|(2131|1800)[0-9]{11})", "er":"2(014|149)[0-9]{11}"};
27
	if (ccType && dojo.lang.has(cardinfo, ccType.toLowerCase())) {
29
	if (ccType && dojo.lang.has(cardinfo, ccType.toLowerCase())) {
28
		return Boolean(value.match(cardinfo[ccType.toLowerCase()]));
30
		return Boolean(value.match(cardinfo[ccType.toLowerCase()]));
29
	} else {
31
	} else {
30
		for (var p in cardinfo) {
32
		for (var p in cardinfo) {
31
			if (value.match("^" + cardinfo[p] + "$") != null) {
33
			if (value.match("^" + cardinfo[p] + "$") != null) {
32
				results.push(p);
34
				results.push(p);
33
			}
35
			}
34
		}
36
		}
35
		return (results.length) ? results.join("|") : false;
37
		return (results.length) ? results.join("|") : false;
36
	}
38
	}
37
};
39
};
38
dojo.validate.isValidCvv = function (value, ccType) {
40
dojo.validate.isValidCvv = function (value, ccType) {
39
	if (typeof value != "string") {
41
	if (typeof value != "string") {
40
		value = String(value);
42
		value = String(value);
41
	}
43
	}
42
	var format;
44
	var format;
43
	switch (ccType.toLowerCase()) {
45
	switch (ccType.toLowerCase()) {
44
	  case "mc":
46
	  case "mc":
45
	  case "ec":
47
	  case "ec":
46
	  case "vi":
48
	  case "vi":
47
	  case "di":
49
	  case "di":
48
		format = "###";
50
		format = "###";
49
		break;
51
		break;
50
	  case "ax":
52
	  case "ax":
51
		format = "####";
53
		format = "####";
52
		break;
54
		break;
53
	  default:
55
	  default:
54
		return false;
56
		return false;
55
	}
57
	}
56
	var flags = {format:format};
58
	var flags = {format:format};
57
	if ((value.length == format.length) && (dojo.validate.isNumberFormat(value, flags))) {
59
	if ((value.length == format.length) && (dojo.validate.isNumberFormat(value, flags))) {
58
		return true;
60
		return true;
59
	}
61
	}
60
	return false;
62
	return false;
61
};
63
};
62
 
64