ng2-validation
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -55,2 +55,28 @@ import { ValidatorFn, AbstractControl } from '@angular/forms'; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of creditCard. | ||
*/ | ||
static creditCard(control: AbstractControl): { | ||
[key: string]: boolean; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of JSON. | ||
*/ | ||
static json(control: AbstractControl): { | ||
[key: string]: boolean; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of base64. | ||
*/ | ||
static base64(control: AbstractControl): { | ||
[key: string]: boolean; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of phone. | ||
*/ | ||
static phone(locale?: string): ValidatorFn; | ||
/** | ||
* Validator that requires controls to have a value of uuid. | ||
*/ | ||
static uuid(version?: string): ValidatorFn; | ||
} |
@@ -15,3 +15,3 @@ "use strict"; | ||
var v = control.value; | ||
return v.length >= rangeLength[0] && v.length <= rangeLength[1] ? null : { 'rangelength': true }; | ||
return v.length >= rangeLength[0] && v.length <= rangeLength[1] ? null : { 'rangeLength': true }; | ||
}; | ||
@@ -104,4 +104,116 @@ }; | ||
var v = control.value; | ||
return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(v) ? null : { 'dateiso': true }; | ||
return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(v) ? null : { 'dateISO': true }; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of creditCard. | ||
*/ | ||
CustomValidators.creditCard = function (control) { | ||
if (lang_1.isPresent(forms_1.Validators.required(control))) | ||
return null; | ||
var v = control.value; | ||
var sanitized = v.replace(/[^0-9]+/g, ''); | ||
// problem with chrome | ||
if (!(/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/.test(sanitized))) { | ||
return { 'creditCard': true }; | ||
} | ||
var sum = 0; | ||
var digit; | ||
var tmpNum; | ||
var shouldDouble; | ||
for (var i = sanitized.length - 1; i >= 0; i--) { | ||
digit = sanitized.substring(i, (i + 1)); | ||
tmpNum = parseInt(digit, 10); | ||
if (shouldDouble) { | ||
tmpNum *= 2; | ||
if (tmpNum >= 10) { | ||
sum += ((tmpNum % 10) + 1); | ||
} | ||
else { | ||
sum += tmpNum; | ||
} | ||
} | ||
else { | ||
sum += tmpNum; | ||
} | ||
shouldDouble = !shouldDouble; | ||
} | ||
if (Boolean((sum % 10) === 0 ? sanitized : false)) { | ||
return null; | ||
} | ||
return { 'creditCard': true }; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of JSON. | ||
*/ | ||
CustomValidators.json = function (control) { | ||
if (lang_1.isPresent(forms_1.Validators.required(control))) | ||
return null; | ||
var v = control.value; | ||
try { | ||
var obj = JSON.parse(v); | ||
if (Boolean(obj) && typeof obj === 'object') { | ||
return null; | ||
} | ||
} | ||
catch (e) { | ||
} | ||
return { 'json': true }; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of base64. | ||
*/ | ||
CustomValidators.base64 = function (control) { | ||
if (lang_1.isPresent(forms_1.Validators.required(control))) | ||
return null; | ||
var v = control.value; | ||
return /^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=|[A-Z0-9+\/]{4})$/i.test(v) ? null : { 'base64': true }; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of phone. | ||
*/ | ||
CustomValidators.phone = function (locale) { | ||
var phones = { | ||
'zh-CN': /^(\+?0?86\-?)?((13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}|170[059]\d{7})$/, | ||
'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, | ||
'en-ZA': /^(\+?27|0)\d{9}$/, | ||
'en-AU': /^(\+?61|0)4\d{8}$/, | ||
'en-HK': /^(\+?852\-?)?[569]\d{3}\-?\d{4}$/, | ||
'fr-FR': /^(\+?33|0)[67]\d{8}$/, | ||
'pt-PT': /^(\+351)?9[1236]\d{7}$/, | ||
'el-GR': /^(\+?30)?(69\d{8})$/, | ||
'en-GB': /^(\+?44|0)7\d{9}$/, | ||
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/, | ||
'en-ZM': /^(\+26)?09[567]\d{7}$/, | ||
'ru-RU': /^(\+?7|8)?9\d{9}$/, | ||
'nb-NO': /^(\+?47)?[49]\d{7}$/, | ||
'nn-NO': /^(\+?47)?[49]\d{7}$/, | ||
'vi-VN': /^(0|\+?84)?((1(2([0-9])|6([2-9])|88|99))|(9((?!5)[0-9])))([0-9]{7})$/, | ||
'en-NZ': /^(\+?64|0)2\d{7,9}$/ | ||
}; | ||
return function (control) { | ||
if (lang_1.isPresent(forms_1.Validators.required(control))) | ||
return null; | ||
var v = control.value; | ||
var pattern = phones[locale] || phones['en-US']; | ||
return (new RegExp(pattern)).test(v) ? null : { 'phone': true }; | ||
}; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value of uuid. | ||
*/ | ||
CustomValidators.uuid = function (version) { | ||
var uuid = { | ||
'3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, | ||
'4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, | ||
'5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, | ||
'all': /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i | ||
}; | ||
return function (control) { | ||
if (lang_1.isPresent(forms_1.Validators.required(control))) | ||
return null; | ||
var v = control.value; | ||
var pattern = uuid[version] || uuid.all; | ||
return (new RegExp(pattern)).test(v) ? null : { 'uuid': true }; | ||
}; | ||
}; | ||
return CustomValidators; | ||
@@ -108,0 +220,0 @@ }()); |
@@ -6,2 +6,4 @@ import { RangeLengthValidator } from "./directives/range-length"; | ||
import { DigitsValidator } from './directives/digits'; | ||
export declare const CUSTOM_FORM_DIRECTIVES: (typeof RangeLengthValidator | typeof MinValidator | typeof MaxValidator | typeof RangeValidator | typeof DigitsValidator)[]; | ||
import { PhoneValidator } from './directives/phone'; | ||
import { UUIDValidator } from './directives/uuid'; | ||
export declare const CUSTOM_FORM_DIRECTIVES: (typeof RangeLengthValidator | typeof MinValidator | typeof MaxValidator | typeof RangeValidator | typeof DigitsValidator | typeof PhoneValidator | typeof UUIDValidator)[]; |
@@ -12,2 +12,7 @@ "use strict"; | ||
var date_iso_1 = require('./directives/date-iso'); | ||
var credit_card_1 = require('./directives/credit-card'); | ||
var json_1 = require('./directives/json'); | ||
var base64_1 = require('./directives/base64'); | ||
var phone_1 = require('./directives/phone'); | ||
var uuid_1 = require('./directives/uuid'); | ||
exports.CUSTOM_FORM_DIRECTIVES = [ | ||
@@ -23,4 +28,9 @@ range_length_1.RangeLengthValidator, | ||
date_1.DateValidator, | ||
date_iso_1.DateISOValidator | ||
date_iso_1.DateISOValidator, | ||
credit_card_1.CreditCardValidator, | ||
json_1.JSONValidator, | ||
base64_1.Base64Validator, | ||
phone_1.PhoneValidator, | ||
uuid_1.UUIDValidator | ||
]; | ||
//# sourceMappingURL=directives.js.map |
@@ -27,3 +27,3 @@ "use strict"; | ||
core_1.Directive({ | ||
selector: '[dateiso][formControlName],[dateiso][formControl],[dateiso][ngModel]', | ||
selector: '[dateISO][formControlName],[dateISO][formControl],[dateISO][ngModel]', | ||
providers: [DATE_ISO_VALIDATOR] | ||
@@ -30,0 +30,0 @@ }), |
@@ -17,3 +17,3 @@ "use strict"; | ||
var _1 = require('../'); | ||
var MAX_LENGTH_VALIDATOR = { | ||
var MAX_VALIDATOR = { | ||
provide: forms_1.NG_VALIDATORS, | ||
@@ -33,3 +33,3 @@ useExisting: core_1.forwardRef(function () { return MaxValidator; }), | ||
selector: '[max][formControlName],[max][formControl],[max][ngModel]', | ||
providers: [MAX_LENGTH_VALIDATOR] | ||
providers: [MAX_VALIDATOR] | ||
}), | ||
@@ -36,0 +36,0 @@ __param(0, core_1.Attribute('max')), |
@@ -17,3 +17,3 @@ "use strict"; | ||
var _1 = require('../'); | ||
var MIN_LENGTH_VALIDATOR = { | ||
var MIN_VALIDATOR = { | ||
provide: forms_1.NG_VALIDATORS, | ||
@@ -33,3 +33,3 @@ useExisting: core_1.forwardRef(function () { return MinValidator; }), | ||
selector: '[min][formControlName],[min][formControl],[min][ngModel]', | ||
providers: [MIN_LENGTH_VALIDATOR] | ||
providers: [MIN_VALIDATOR] | ||
}), | ||
@@ -36,0 +36,0 @@ __param(0, core_1.Attribute('min')), |
@@ -31,6 +31,6 @@ "use strict"; | ||
core_1.Directive({ | ||
selector: '[rangelength][formControlName],[rangelength][formControl],[rangelength][ngModel]', | ||
selector: '[rangeLength][formControlName],[rangeLength][formControl],[rangeLength][ngModel]', | ||
providers: [RANGE_LENGTH_VALIDATOR] | ||
}), | ||
__param(0, core_1.Attribute('rangelength')), | ||
__param(0, core_1.Attribute('rangeLength')), | ||
__metadata('design:paramtypes', [String]) | ||
@@ -37,0 +37,0 @@ ], RangeLengthValidator); |
{ | ||
"name": "ng2-validation", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "angular2 validation", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
59
998
0
62813