Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
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:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.validate.creditCard");
14
dojo.require("dojo.lang.common");
15
dojo.require("dojo.validate.common");
16
dojo.validate.isValidCreditCard = function (value, ccType) {
17
	if (value && ccType && ((ccType.toLowerCase() == "er" || dojo.validate.isValidLuhn(value)) && (dojo.validate.isValidCreditCardNumber(value, ccType.toLowerCase())))) {
18
		return true;
19
	}
20
	return false;
21
};
22
dojo.validate.isValidCreditCardNumber = function (value, ccType) {
23
	if (typeof value != "string") {
24
		value = String(value);
25
	}
26
	value = value.replace(/[- ]/g, "");
27
	var results = [];
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}"};
29
	if (ccType && dojo.lang.has(cardinfo, ccType.toLowerCase())) {
30
		return Boolean(value.match(cardinfo[ccType.toLowerCase()]));
31
	} else {
32
		for (var p in cardinfo) {
33
			if (value.match("^" + cardinfo[p] + "$") != null) {
34
				results.push(p);
35
			}
36
		}
37
		return (results.length) ? results.join("|") : false;
38
	}
39
};
40
dojo.validate.isValidCvv = function (value, ccType) {
41
	if (typeof value != "string") {
42
		value = String(value);
43
	}
44
	var format;
45
	switch (ccType.toLowerCase()) {
46
	  case "mc":
47
	  case "ec":
48
	  case "vi":
49
	  case "di":
50
		format = "###";
51
		break;
52
	  case "ax":
53
		format = "####";
54
		break;
55
	  default:
56
		return false;
57
	}
58
	var flags = {format:format};
59
	if ((value.length == format.length) && (dojo.validate.isNumberFormat(value, flags))) {
60
		return true;
61
	}
62
	return false;
63
};
64