UNPKG

ng2-validators

Version:

An implementation of angular validators for Angular 2

93 lines 3.14 kB
import { Util } from './../util'; var visaRegex = '^(?:4[0-9]{12})(?:[0-9]{3})?$'; var americanExpressRegex = '^(?:3[47][0-9]{13})$'; var maestroRegex = '^(?:(?:5[0678]\\d\\d|6304|6390|67\\d\\d)\\d{8,15})$'; var jcbRegex = '^(?:(?:2131|1800|35\\d{3})\\d{11})$'; var discoverRegex = '^(?:6(?:011|5[0-9]{2})(?:[0-9]{12}))$'; var dinersclubRegex = '^(?:3(?:0[0-5]|[68][0-9])[0-9]{11})$'; var mastercardRegex = '^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$'; var CreditCardValidators = (function () { function CreditCardValidators() { } CreditCardValidators.isCreditCard = function (control) { if (Util.isNotPresent(control)) return undefined; if (new RegExp(americanExpressRegex + '|' + visaRegex + '|' + maestroRegex + '|' + jcbRegex + '|' + discoverRegex + '|' + mastercardRegex + '|' + dinersclubRegex).test(control.value)) { return undefined; } return { 'creditcard': true }; }; ; CreditCardValidators.americanExpress = function (control) { if (Util.isNotPresent(control)) return undefined; if (new RegExp(americanExpressRegex).test(control.value)) { return undefined; } return { 'americanExpress': true }; }; ; CreditCardValidators.dinersclub = function (control) { if (Util.isNotPresent(control)) return undefined; if (new RegExp(dinersclubRegex).test(control.value)) { return undefined; } return { 'dinersclub': true }; }; ; CreditCardValidators.discover = function (control) { if (Util.isNotPresent(control)) return undefined; if (new RegExp(discoverRegex).test(control.value)) { return undefined; } return { 'discover': true }; }; ; CreditCardValidators.jcb = function (control) { if (Util.isNotPresent(control)) return undefined; if (new RegExp(jcbRegex).test(control.value)) { return undefined; } return { 'jcb': true }; }; ; CreditCardValidators.maestro = function (control) { if (Util.isNotPresent(control)) return undefined; if (new RegExp(maestroRegex).test(control.value)) { return undefined; } return { 'maestro': true }; }; ; CreditCardValidators.mastercard = function (control) { if (Util.isNotPresent(control)) return undefined; if (new RegExp(mastercardRegex).test(control.value)) { return undefined; } return { 'mastercard': true }; }; ; CreditCardValidators.visa = function (control) { if (Util.isNotPresent(control)) return undefined; if (new RegExp(visaRegex).test(control.value)) { return undefined; } return { 'visa': true }; }; ; return CreditCardValidators; }()); export { CreditCardValidators }; //# sourceMappingURL=creditcard-validators.js.map