ng2-validators
Version:
An implementation of angular validators for Angular 2
1,172 lines (1,124 loc) • 39.3 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('google-libphonenumber'), require('@angular/core'), require('@angular/forms')) :
typeof define === 'function' && define.amd ? define(['exports', 'google-libphonenumber', '@angular/core', '@angular/forms'], factory) :
(factory((global.ng2 = global.ng2 || {}, global.ng2.validators = global.ng2.validators || {}),global.google.libphonenumber,global.ng.core,global.ng.forms));
}(this, (function (exports,googleLibphonenumber,_angular_core,_angular_forms) { 'use strict';
var Util = (function () {
function Util() {
}
Util.isNotPresent = function (control) {
var value = control.value;
if (value === undefined || value === null) {
return true;
}
return value !== '' ? false : true;
};
return Util;
}());
// tslint:disable-next-line:variable-name
var PasswordValidators = (function () {
function PasswordValidators() {
}
PasswordValidators.repeatCharacterRegexRule = function (repeatCount) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var repeatDec = repeatCount - 1;
var pattern = '([^\\x00-\\x1F])\\1{' + repeatDec + '}';
if (control.value !== '' && new RegExp(pattern).test(control.value)) {
return { 'repeatCharacterRegexRule': { 'repeatCount': repeatCount } };
}
return undefined;
};
return validator;
};
PasswordValidators.allowedCharacterRule = function (allowedChars) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
var valid = true;
var invalidChars = [];
for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
var char = value_1[_i];
if (allowedChars.indexOf(char) === -1) {
valid = false;
if (invalidChars.indexOf(char) === -1) {
invalidChars.push(char);
}
}
}
if (!valid) {
return { 'allowedCharacterRule': { 'invalidChars': invalidChars, 'allowedChars': allowedChars } };
}
return undefined;
};
return validator;
};
PasswordValidators.alphabeticalCharacterRule = function (amount) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (value.length === 0) {
return undefined;
}
var pattern = /[^A-Za-z]+/g;
var stripped = value.replace(pattern, '');
if (stripped.length < amount) {
return { 'alphabeticalCharacterRule': { 'required': amount, 'actual': stripped.length } };
}
return undefined;
};
return validator;
};
PasswordValidators.digitCharacterRule = function (amount) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (value.length === 0) {
return undefined;
}
var pattern = /[^0-9\.]+/g;
var stripped = value.replace(pattern, '');
if (stripped.length < amount) {
return { 'digitCharacterRule': { 'required': amount, 'actual': stripped.length } };
}
return undefined;
};
return validator;
};
PasswordValidators.lowercaseCharacterRule = function (amount) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (value.length === 0) {
return undefined;
}
var pattern = /[^a-z]+/g;
var stripped = value.replace(pattern, '');
if (stripped.length < amount) {
return { 'lowercaseCharacterRule': { 'required': amount, 'actual': stripped.length } };
}
return undefined;
};
return validator;
};
PasswordValidators.uppercaseCharacterRule = function (amount) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (value.length === 0) {
return undefined;
}
var pattern = /[^A-Z]+/g;
var stripped = value.replace(pattern, '');
if (stripped.length < amount) {
return { 'uppercaseCharacterRule': { 'required': amount, 'actual': stripped.length } };
}
return undefined;
};
return validator;
};
PasswordValidators.specialCharacterRule = function (amount) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (value.length === 0) {
return undefined;
}
var pattern = /[\w\s]+/g;
var stripped = value.replace(pattern, '');
if (stripped.length < amount) {
return { 'specialCharacterRule': { 'required': amount, 'actual': stripped.length } };
}
return undefined;
};
return validator;
};
PasswordValidators.mismatchedPasswords = function (passwordControlName, confirmPasswordControlName) {
var validator = function (group) {
var newPasswordValue = group.get(passwordControlName ? passwordControlName : 'newPassword').value;
var newPasswordConfirmValue = group.get(confirmPasswordControlName ? confirmPasswordControlName : 'confirmPassword').value;
if (newPasswordValue !== newPasswordConfirmValue) {
group.get(confirmPasswordControlName ? confirmPasswordControlName : 'confirmPassword')
.setErrors({ 'mismatchedPasswords': true });
return { 'mismatchedPasswords': true };
}
return undefined;
};
return validator;
};
return PasswordValidators;
}());
var EmailValidators = (function () {
function EmailValidators() {
}
EmailValidators.simple = function (control) {
if (Util.isNotPresent(control))
return undefined;
var pattern = '^.+@.+\\..+$';
if (new RegExp(pattern).test(control.value)) {
return undefined;
}
return { 'simpleEmailRule': true };
};
// https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
EmailValidators.normal = function (control) {
if (Util.isNotPresent(control))
return undefined;
// tslint:disable-next-line:max-line-length
var pattern = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
if (pattern.test(control.value)) {
return undefined;
}
return { 'normalEmailRule': true };
};
return EmailValidators;
}());
var UniversalValidators = (function () {
function UniversalValidators() {
}
UniversalValidators.noWhitespace = function (control) {
if (Util.isNotPresent(control))
return undefined;
var pattern = '\\s';
if (new RegExp(pattern).test(control.value)) {
return { 'noWhitespaceRequired': true };
}
return undefined;
};
UniversalValidators.noEmptyString = function (control) {
if (Util.isNotPresent(control))
return undefined;
if (control.value.trim().length === 0) {
return { 'noEmptyString': true };
}
return undefined;
};
UniversalValidators.isNumber = function (control) {
if (Util.isNotPresent(control))
return undefined;
if (isNaN(control.value)) {
return { 'numberRequired': true };
}
return undefined;
};
UniversalValidators.isInRange = function (minValue, maxValue) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
if (isNaN(control.value)) {
return { 'numberRequired': true };
}
if (+control.value < minValue) {
return { 'rangeValueToSmall': { 'requiredMinValue': minValue, 'requiredMaxValue': maxValue, 'actual': control.value } };
}
if (+control.value > maxValue) {
return { 'rangeValueToBig': { 'requiredMinValue': minValue, 'requiredMaxValue': maxValue, 'actual': control.value } };
}
else {
return undefined;
}
};
return validator;
};
UniversalValidators.minLength = function (minLength) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (value.length >= minLength) {
return undefined;
}
return { 'minLength': { 'requiredMinLength': minLength, 'actualLength': value.length } };
};
return validator;
};
UniversalValidators.maxLength = function (maxLength) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (maxLength >= value.length) {
return undefined;
}
return { 'maxLength': { 'requiredMaxLength': maxLength, 'actualLength': value.length } };
};
return validator;
};
UniversalValidators.min = function (min) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (isNaN(control.value)) {
return { 'numberRequired': true };
}
if (+value >= min) {
return undefined;
}
return { 'min': { 'required': min, 'actual': control.value } };
};
return validator;
};
UniversalValidators.max = function (max) {
var validator = function (control) {
if (Util.isNotPresent(control))
return undefined;
var value = control.value;
if (isNaN(control.value)) {
return { 'numberRequired': true };
}
if (max >= +value) {
return undefined;
}
return { 'max': { 'required': max, 'actual': control.value } };
};
return validator;
};
return UniversalValidators;
}());
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;
}());
var regionsCode = {
// Region code for global networks (e.g. +800 numbers).
UN001: '001',
AD: 'AD',
AE: 'AE',
AF: 'AF',
AG: 'AG',
AI: 'AI',
AL: 'AL',
AM: 'AM',
AN: 'AN',
AO: 'AO',
AQ: 'AQ',
AR: 'AR',
AS: 'AS',
AT: 'AT',
AU: 'AU',
AW: 'AW',
AX: 'AX',
AZ: 'AZ',
BA: 'BA',
BB: 'BB',
BD: 'BD',
BE: 'BE',
BF: 'BF',
BG: 'BG',
BH: 'BH',
BI: 'BI',
BJ: 'BJ',
BL: 'BL',
BM: 'BM',
BN: 'BN',
BO: 'BO',
BR: 'BR',
BS: 'BS',
BT: 'BT',
BV: 'BV',
BW: 'BW',
BY: 'BY',
BZ: 'BZ',
CA: 'CA',
CC: 'CC',
CD: 'CD',
CF: 'CF',
CG: 'CG',
CH: 'CH',
CI: 'CI',
CK: 'CK',
CL: 'CL',
CM: 'CM',
CN: 'CN',
CO: 'CO',
CR: 'CR',
CU: 'CU',
CV: 'CV',
CX: 'CX',
CY: 'CY',
CZ: 'CZ',
DE: 'DE',
DJ: 'DJ',
DK: 'DK',
DM: 'DM',
DO: 'DO',
DZ: 'DZ',
EC: 'EC',
EE: 'EE',
EG: 'EG',
EH: 'EH',
ER: 'ER',
ES: 'ES',
ET: 'ET',
FI: 'FI',
FJ: 'FJ',
FK: 'FK',
FM: 'FM',
FO: 'FO',
FR: 'FR',
GA: 'GA',
GB: 'GB',
GD: 'GD',
GE: 'GE',
GF: 'GF',
GG: 'GG',
GH: 'GH',
GI: 'GI',
GL: 'GL',
GM: 'GM',
GN: 'GN',
GP: 'GP',
GQ: 'GQ',
GR: 'GR',
GS: 'GS',
GT: 'GT',
GU: 'GU',
GW: 'GW',
GY: 'GY',
HK: 'HK',
HM: 'HM',
HN: 'HN',
HR: 'HR',
HT: 'HT',
HU: 'HU',
ID: 'ID',
IE: 'IE',
IL: 'IL',
IM: 'IM',
IN: 'IN',
IO: 'IO',
IQ: 'IQ',
IR: 'IR',
IS: 'IS',
IT: 'IT',
JE: 'JE',
JM: 'JM',
JO: 'JO',
JP: 'JP',
KE: 'KE',
KG: 'KG',
KH: 'KH',
KI: 'KI',
KM: 'KM',
KN: 'KN',
KP: 'KP',
KR: 'KR',
KW: 'KW',
KY: 'KY',
KZ: 'KZ',
LA: 'LA',
LB: 'LB',
LC: 'LC',
LI: 'LI',
LK: 'LK',
LR: 'LR',
LS: 'LS',
LT: 'LT',
LU: 'LU',
LV: 'LV',
LY: 'LY',
MA: 'MA',
MC: 'MC',
MD: 'MD',
ME: 'ME',
MF: 'MF',
MG: 'MG',
MH: 'MH',
MK: 'MK',
ML: 'ML',
MM: 'MM',
MN: 'MN',
MO: 'MO',
MP: 'MP',
MQ: 'MQ',
MR: 'MR',
MS: 'MS',
MT: 'MT',
MU: 'MU',
MV: 'MV',
MW: 'MW',
MX: 'MX',
MY: 'MY',
MZ: 'MZ',
NA: 'NA',
NC: 'NC',
NE: 'NE',
NF: 'NF',
NG: 'NG',
NI: 'NI',
NL: 'NL',
NO: 'NO',
NP: 'NP',
NR: 'NR',
NU: 'NU',
NZ: 'NZ',
OM: 'OM',
PA: 'PA',
PE: 'PE',
PF: 'PF',
PG: 'PG',
PH: 'PH',
PK: 'PK',
PL: 'PL',
PM: 'PM',
PN: 'PN',
PR: 'PR',
PS: 'PS',
PT: 'PT',
PW: 'PW',
PY: 'PY',
QA: 'QA',
RE: 'RE',
RO: 'RO',
RS: 'RS',
RU: 'RU',
RW: 'RW',
SA: 'SA',
SB: 'SB',
SC: 'SC',
SD: 'SD',
SE: 'SE',
SG: 'SG',
SH: 'SH',
SI: 'SI',
SJ: 'SJ',
SK: 'SK',
SL: 'SL',
SM: 'SM',
SN: 'SN',
SO: 'SO',
SR: 'SR',
ST: 'ST',
SV: 'SV',
SY: 'SY',
SZ: 'SZ',
TC: 'TC',
TD: 'TD',
TF: 'TF',
TG: 'TG',
TH: 'TH',
TJ: 'TJ',
TK: 'TK',
TL: 'TL',
TM: 'TM',
TN: 'TN',
TO: 'TO',
TR: 'TR',
TT: 'TT',
TV: 'TV',
TW: 'TW',
TZ: 'TZ',
UA: 'UA',
UG: 'UG',
UM: 'UM',
US: 'US',
UY: 'UY',
UZ: 'UZ',
VA: 'VA',
VC: 'VC',
VE: 'VE',
VG: 'VG',
VI: 'VI',
VN: 'VN',
VU: 'VU',
WF: 'WF',
WS: 'WS',
YE: 'YE',
YT: 'YT',
ZA: 'ZA',
ZM: 'ZM',
ZW: 'ZW',
// Official code for the unknown region.
ZZ: 'ZZ'
};
var PhoneValidators = (function () {
function PhoneValidators() {
}
PhoneValidators.checkRegionCode = function (local) {
return !(regionsCode[local] === undefined);
};
PhoneValidators.isValidRegionCode = function (control) {
if (Util.isNotPresent(control)) {
return undefined;
}
if (!PhoneValidators.checkRegionCode(control.value)) {
return { 'noValidRegionCode': true };
}
return undefined;
};
PhoneValidators.isPhoneNumber = function (local) {
var validator = function (control) {
if (Util.isNotPresent(control)) {
return undefined;
}
if (!PhoneValidators.checkRegionCode(local)) {
return { 'noValidRegionCode': true };
}
var phoneParser = googleLibphonenumber.PhoneNumberUtil.getInstance();
var error = { 'noPhoneNumber': true };
try {
var phoneNumber = phoneParser.parse(control.value, local);
if (phoneParser.isValidNumber(phoneNumber)) {
error = undefined;
}
}
catch (err) {
error = { 'noPhoneNumber': true };
}
return error;
};
return validator;
};
PhoneValidators.isPossibleNumberWithReason = function (local) {
var validator = function (control) {
if (Util.isNotPresent(control)) {
return undefined;
}
if (!PhoneValidators.checkRegionCode(local)) {
return { 'noValidRegionCode': true };
}
var phoneParser = googleLibphonenumber.PhoneNumberUtil.getInstance();
var error = { 'noPhoneNumber': true };
try {
var phoneNumber = phoneParser.parse(control.value, local);
var reason = phoneParser.isPossibleNumberWithReason(phoneNumber);
switch (reason) {
case googleLibphonenumber.PhoneNumberUtil.ValidationResult.IS_POSSIBLE:
error = undefined;
break;
case googleLibphonenumber.PhoneNumberUtil.ValidationResult.TOO_LONG:
error = { 'phoneNumberTooLong': true };
break;
case googleLibphonenumber.PhoneNumberUtil.ValidationResult.TOO_SHORT:
error = { 'phoneNumberTooShort': true };
break;
case googleLibphonenumber.PhoneNumberUtil.ValidationResult.INVALID_COUNTRY_CODE:
error = { 'phoneNumberInvalidCountryCode': true };
break;
default:
error = { 'noPhoneNumber': true };
break;
}
}
catch (err) {
error = { 'noPhoneNumber': true };
}
return error;
};
return validator;
};
return PhoneValidators;
}());
var PasswordValidatorDirective = (function () {
function PasswordValidatorDirective() {
this.repeatCharacter = 4;
this.alphabeticalCharacter = 1;
this.digitCharacter = 1;
this.lowercaseCharacter = 1;
this.uppercaseCharacter = 1;
}
PasswordValidatorDirective.prototype.ngOnInit = function () {
this.repeatCharacterValidator = PasswordValidators.repeatCharacterRegexRule(this.repeatCharacter);
this.alphabeticalCharacterValidator = PasswordValidators.alphabeticalCharacterRule(this.alphabeticalCharacter);
this.digitCharacterValidator = PasswordValidators.digitCharacterRule(this.digitCharacter);
this.lowercaseCharacterValidator = PasswordValidators.lowercaseCharacterRule(this.lowercaseCharacter);
this.uppercaseCharacterValidator = PasswordValidators.uppercaseCharacterRule(this.uppercaseCharacter);
};
PasswordValidatorDirective.prototype.validate = function (c) {
var compose = _angular_forms.Validators.compose([this.repeatCharacterValidator,
this.digitCharacterValidator, this.alphabeticalCharacterValidator,
this.lowercaseCharacterValidator, this.uppercaseCharacterValidator]);
return compose(c);
};
return PasswordValidatorDirective;
}());
PasswordValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[password][formControlName],[password][formControl],[password][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return PasswordValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
PasswordValidatorDirective.ctorParameters = function () { return []; };
PasswordValidatorDirective.propDecorators = {
'repeatCharacter': [{ type: _angular_core.Input },],
'alphabeticalCharacter': [{ type: _angular_core.Input },],
'digitCharacter': [{ type: _angular_core.Input },],
'lowercaseCharacter': [{ type: _angular_core.Input },],
'uppercaseCharacter': [{ type: _angular_core.Input },],
};
var EmailValidatorDirective = (function () {
function EmailValidatorDirective() {
this.email = 'normal';
}
EmailValidatorDirective.prototype.ngOnInit = function () {
switch (this.email) {
case 'simple':
this.validator = EmailValidators.simple;
break;
case 'normal':
this.validator = EmailValidators.normal;
break;
default:
this.validator = EmailValidators.normal;
break;
}
};
EmailValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return EmailValidatorDirective;
}());
EmailValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[email][formControlName],[email][formControl],[email][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return EmailValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
EmailValidatorDirective.ctorParameters = function () { return []; };
EmailValidatorDirective.propDecorators = {
'email': [{ type: _angular_core.Input },],
};
var WhiteSpaceValidatorDirective = (function () {
function WhiteSpaceValidatorDirective() {
}
WhiteSpaceValidatorDirective.prototype.ngOnInit = function () {
this.validator = UniversalValidators.noWhitespace;
};
WhiteSpaceValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return WhiteSpaceValidatorDirective;
}());
WhiteSpaceValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[noWhitespace][formControlName],[noWhitespace][formControl],[noWhitespace][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return WhiteSpaceValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
WhiteSpaceValidatorDirective.ctorParameters = function () { return []; };
var EmptyStringValidatorDirective = (function () {
function EmptyStringValidatorDirective() {
}
EmptyStringValidatorDirective.prototype.ngOnInit = function () {
this.validator = UniversalValidators.noEmptyString;
};
EmptyStringValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return EmptyStringValidatorDirective;
}());
EmptyStringValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[noEmptyString][formControlName],[noEmptyString][formControl],[noEmptyString][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return EmptyStringValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
EmptyStringValidatorDirective.ctorParameters = function () { return []; };
var IsNumberValidatorDirective = (function () {
function IsNumberValidatorDirective() {
}
IsNumberValidatorDirective.prototype.ngOnInit = function () {
this.validator = UniversalValidators.isNumber;
};
IsNumberValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return IsNumberValidatorDirective;
}());
IsNumberValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[isNumber][formControlName],[isNumber][formControl],[isNumber][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return IsNumberValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
IsNumberValidatorDirective.ctorParameters = function () { return []; };
var IsInRangeValidatorDirective = (function () {
function IsInRangeValidatorDirective() {
}
IsInRangeValidatorDirective.prototype.ngOnInit = function () {
this.validator = UniversalValidators.isInRange(this.minValue, this.maxValue);
};
IsInRangeValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return IsInRangeValidatorDirective;
}());
IsInRangeValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[isInRange][formControlName],[isInRange][formControl],[isInRange][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return IsInRangeValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
IsInRangeValidatorDirective.ctorParameters = function () { return []; };
IsInRangeValidatorDirective.propDecorators = {
'minValue': [{ type: _angular_core.Input },],
'maxValue': [{ type: _angular_core.Input },],
};
var MaxValidatorDirective = (function () {
function MaxValidatorDirective() {
}
MaxValidatorDirective.prototype.ngOnInit = function () {
this.validator = UniversalValidators.max(this.max);
};
MaxValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return MaxValidatorDirective;
}());
MaxValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[max][formControlName],[max][formControl],[max][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return MaxValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
MaxValidatorDirective.ctorParameters = function () { return []; };
MaxValidatorDirective.propDecorators = {
'max': [{ type: _angular_core.Input },],
};
var MinValidatorDirective = (function () {
function MinValidatorDirective() {
}
MinValidatorDirective.prototype.ngOnInit = function () {
this.validator = UniversalValidators.min(this.min);
};
MinValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return MinValidatorDirective;
}());
MinValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[min][formControlName],[min][formControl],[min][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return MinValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
MinValidatorDirective.ctorParameters = function () { return []; };
MinValidatorDirective.propDecorators = {
'min': [{ type: _angular_core.Input },],
};
var CreditCardValidatorDirective = (function () {
function CreditCardValidatorDirective() {
this.creditCard = 'all';
}
CreditCardValidatorDirective.prototype.ngOnInit = function () {
switch (this.creditCard) {
case 'all':
this.validator = CreditCardValidators.isCreditCard;
break;
case 'americanExpress':
this.validator = CreditCardValidators.americanExpress;
break;
case 'dinersclub':
this.validator = CreditCardValidators.dinersclub;
break;
case 'discover':
this.validator = CreditCardValidators.discover;
break;
case 'jcb':
this.validator = CreditCardValidators.jcb;
break;
case 'maestro':
this.validator = CreditCardValidators.maestro;
break;
case 'mastercard':
this.validator = CreditCardValidators.mastercard;
break;
case 'visa':
this.validator = CreditCardValidators.visa;
break;
default:
this.validator = CreditCardValidators.isCreditCard;
break;
}
};
CreditCardValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return CreditCardValidatorDirective;
}());
CreditCardValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[creditCard][formControlName],[creditCard][formControl],[creditCard][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return CreditCardValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
CreditCardValidatorDirective.ctorParameters = function () { return []; };
CreditCardValidatorDirective.propDecorators = {
'creditCard': [{ type: _angular_core.Input },],
};
var PossiblePhoneValidatorDirective = (function () {
function PossiblePhoneValidatorDirective() {
this.possiblePhone = 'US';
}
PossiblePhoneValidatorDirective.prototype.ngOnInit = function () {
this.validator = PhoneValidators.isPossibleNumberWithReason(this.possiblePhone);
};
PossiblePhoneValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return PossiblePhoneValidatorDirective;
}());
PossiblePhoneValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[possiblePhone][formControlName],[possiblePhone][formControl],[possiblePhone][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return PossiblePhoneValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
PossiblePhoneValidatorDirective.ctorParameters = function () { return []; };
PossiblePhoneValidatorDirective.propDecorators = {
'possiblePhone': [{ type: _angular_core.Input },],
};
var PhoneValidatorDirective = (function () {
function PhoneValidatorDirective() {
this.phone = 'US';
}
PhoneValidatorDirective.prototype.ngOnInit = function () {
this.validator = PhoneValidators.isPhoneNumber(this.phone);
};
PhoneValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return PhoneValidatorDirective;
}());
PhoneValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[phone][formControlName],[phone][formControl],[phone][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return PhoneValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
PhoneValidatorDirective.ctorParameters = function () { return []; };
PhoneValidatorDirective.propDecorators = {
'phone': [{ type: _angular_core.Input },],
};
var CountryCodeValidatorDirective = (function () {
function CountryCodeValidatorDirective() {
}
CountryCodeValidatorDirective.prototype.ngOnInit = function () {
this.validator = PhoneValidators.isValidRegionCode;
};
CountryCodeValidatorDirective.prototype.validate = function (c) {
return this.validator(c);
};
return CountryCodeValidatorDirective;
}());
CountryCodeValidatorDirective.decorators = [
{ type: _angular_core.Directive, args: [{
selector: '[countryCode][formControlName],[countryCode][formControl],[countryCode][ngModel]',
providers: [{
provide: _angular_forms.NG_VALIDATORS,
// tslint:disable-next-line:no-forward-ref
useExisting: _angular_core.forwardRef(function () { return CountryCodeValidatorDirective; }),
multi: true
}]
},] },
];
/** @nocollapse */
CountryCodeValidatorDirective.ctorParameters = function () { return []; };
var ValidatorsModule = (function () {
function ValidatorsModule() {
}
return ValidatorsModule;
}());
ValidatorsModule.decorators = [
{ type: _angular_core.NgModule, args: [{
declarations: [CreditCardValidatorDirective,
EmailValidatorDirective,
PasswordValidatorDirective,
IsInRangeValidatorDirective,
IsNumberValidatorDirective,
MaxValidatorDirective,
MinValidatorDirective,
WhiteSpaceValidatorDirective,
PhoneValidatorDirective,
PossiblePhoneValidatorDirective,
EmptyStringValidatorDirective,
CountryCodeValidatorDirective],
exports: [CreditCardValidatorDirective,
EmailValidatorDirective,
PasswordValidatorDirective,
IsInRangeValidatorDirective,
IsNumberValidatorDirective,
MaxValidatorDirective,
MinValidatorDirective,
WhiteSpaceValidatorDirective,
PhoneValidatorDirective,
PossiblePhoneValidatorDirective,
EmptyStringValidatorDirective,
CountryCodeValidatorDirective]
},] },
];
/** @nocollapse */
ValidatorsModule.ctorParameters = function () { return []; };
// validators
exports.PasswordValidators = PasswordValidators;
exports.EmailValidators = EmailValidators;
exports.UniversalValidators = UniversalValidators;
exports.CreditCardValidators = CreditCardValidators;
exports.PhoneValidators = PhoneValidators;
exports.PasswordValidatorDirective = PasswordValidatorDirective;
exports.EmailValidatorDirective = EmailValidatorDirective;
exports.IsInRangeValidatorDirective = IsInRangeValidatorDirective;
exports.IsNumberValidatorDirective = IsNumberValidatorDirective;
exports.MaxValidatorDirective = MaxValidatorDirective;
exports.MinValidatorDirective = MinValidatorDirective;
exports.WhiteSpaceValidatorDirective = WhiteSpaceValidatorDirective;
exports.EmptyStringValidatorDirective = EmptyStringValidatorDirective;
exports.CreditCardValidatorDirective = CreditCardValidatorDirective;
exports.PhoneValidatorDirective = PhoneValidatorDirective;
exports.CountryCodeValidatorDirective = CountryCodeValidatorDirective;
exports.PossiblePhoneValidatorDirective = PossiblePhoneValidatorDirective;
exports.ValidatorsModule = ValidatorsModule;
Object.defineProperty(exports, '__esModule', { value: true });
})));