Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.validate.creditCard");
12
dojo.require("dojo.lang.common");
13
dojo.require("dojo.validate.common");
14
dojo.validate.isValidCreditCard = function (value, ccType) {
15
	if (value && ccType && ((ccType.toLowerCase() == "er" || dojo.validate.isValidLuhn(value)) && (dojo.validate.isValidCreditCardNumber(value, ccType.toLowerCase())))) {
16
		return true;
17
	}
18
	return false;
19
};
20
dojo.validate.isValidCreditCardNumber = function (value, ccType) {
21
	if (typeof value != "string") {
22
		value = String(value);
23
	}
24
	value = value.replace(/[- ]/g, "");
25
	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}"};
27
	if (ccType && dojo.lang.has(cardinfo, ccType.toLowerCase())) {
28
		return Boolean(value.match(cardinfo[ccType.toLowerCase()]));
29
	} else {
30
		for (var p in cardinfo) {
31
			if (value.match("^" + cardinfo[p] + "$") != null) {
32
				results.push(p);
33
			}
34
		}
35
		return (results.length) ? results.join("|") : false;
36
	}
37
};
38
dojo.validate.isValidCvv = function (value, ccType) {
39
	if (typeof value != "string") {
40
		value = String(value);
41
	}
42
	var format;
43
	switch (ccType.toLowerCase()) {
44
	  case "mc":
45
	  case "ec":
46
	  case "vi":
47
	  case "di":
48
		format = "###";
49
		break;
50
	  case "ax":
51
		format = "####";
52
		break;
53
	  default:
54
		return false;
55
	}
56
	var flags = {format:format};
57
	if ((value.length == format.length) && (dojo.validate.isNumberFormat(value, flags))) {
58
		return true;
59
	}
60
	return false;
61
};
62