Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static creditCard(control: AbstractControl): {[key: string]: boolean} {
if (isPresent(Validators.required(control))) return null;
let v: string = control.value;
let 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};
}
let sum = 0;
let digit;
let tmpNum;
let shouldDouble;
for (let i = sanitized.length - 1; i >= 0; i--) {
digit = sanitized.substring(i, (i + 1));
export function dateIsEndOfMonth(control: AbstractControl): { [key: string]: any } {
if (isPresent(Validators.required(control)))
return null;
const isISOdate = /\d{4}-\d{2}-\d{2}/.test(control.value);
if (!isISOdate)
return { 'dateIsEndOfMonth': true };
const isValidDate = isDate(control.value);
if (!isValidDate)
return { 'dateIsEndOfMonth': true };
const date = new Date(control.value.replace(/-/g, '\/'));
return !isEndOfMonth(date) ? { 'dateIsEndOfMonth': true } : null;
}
static digits(control: AbstractControl): {[key: string]: boolean} {
if (isPresent(Validators.required(control))) return null;
let v: string = control.value;
return /^\d+$/.test(v) ? null : {'digits': true};
}
const metaValidator = (control: AbstractControl): { [key: string]: any } => {
if (isPresent(Validators.required(control)) || !control.touched) {
return null;
}
const errorMsg = UIMeta.validationError(that.context);
return isPresent(errorMsg) ? {
'metavalid': {'msg': errorMsg}
} : null;
};
return (control: AbstractControl): {[key: string]: any} => {
if (!isPresent(range)) return null;
if (isPresent(Validators.required(control))) return null;
let v: number = +control.value;
return v >= range[0] && v <= range[1] ? null : {actualValue: v, requiredValue: range, range: true};
};
};
export const time: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (utilsBr.isPresent(Validators.required(control))) {
return null;
}
const v: string = control.value;
return validateBr.time(v) ? null : {time: true};
}
export const cnpj: ValidatorFn = (control: AbstractControl): {[key: string]: boolean} => {
if (utilsBr.isPresent(Validators.required(control))) {
return null;
}
const v: string = control.value;
return validateBr.cnpj(v) ? null : {cnpj: true};
}
function (c) {
if (!!Validators.required(c) || (!maxValue && maxValue !== 0)) {
return undefined;
}
/** @type {?} */
var v = c.value;
return v > maxValue ? { max: { maxValue: maxValue, actualValue: v } } : undefined;
});
return func;
return (control: AbstractControl): {[key: string]: any} => {
if (isPresent(Validators.required(control))) return null;
let d: Date = new Date(control.value);
if (!isDate(d)) return {minDate: true};
if (minDate instanceof Function) minDate = minDate();
return d >= new Date(minDate) ? null : {minDate: true};
};
}
return (c: AbstractControl): {[key: string]: any} => {
if (!!Validators.required(c) || !!TdNumberRequiredValidator.validate(c) || (!minValue && minValue !== 0)) {
return undefined;
}
let v: number = c.value;
return v < minValue ?
{ min: {minValue: minValue, actualValue: v} } :
undefined;
};
};