How to use the @angular/forms.Validators.required function in @angular/forms

To help you get started, we’ve selected a few @angular/forms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yuyang041060120 / ng2-validation / src / custom-validators.ts View on Github external
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));
github alvachien / acgallery / src / app / directives / validator.ts View on Github external
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;
}
github yuyang041060120 / ng2-validation / src / custom-validators.ts View on Github external
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};
  }
github ngx-meta / rules / libs / rules / src / lib / metaui / layout / meta-form / meta-form-row / meta-form-row.component.ts View on Github external
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;
    };
github yuyang041060120 / ng2-validation / src / range / validator.ts View on Github external
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};
  };
};
github mariohmol / ng-brazil / ng-brazil / src / time / validator.ts View on Github external
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};
}
github mariohmol / ng-brazil / ng-brazil / src / cnpj / validator.ts View on Github external
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};
}
github Teradata / covalent-nightly / fesm5 / covalent-core-common.js View on Github external
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;
github yuyang041060120 / ng2-validation / src / custom-validators.ts View on Github external
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};
    };
  }
github Teradata / covalent-nightly / common / forms / validators / min / min.validator.ts View on Github external
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;
    };
  };