How to use ngx-validators - 10 common examples

To help you get started, we’ve selected a few ngx-validators 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 Nightapes / ngx-validators / examples / src / app / reactive-forms / email-validator / email-validator.component.ts View on Github external
import { EmailValidators } from 'ngx-validators';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-reactive-email-validator',
  templateUrl: './email-validator.component.html',
  styleUrls: ['./email-validator.component.css']
})
export class ReactiveFormEmailValidatorComponent implements OnInit {

  form: FormGroup;
  email = new FormControl('', Validators.compose([EmailValidators.normal]));
  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {
    this.form = this._fb.group({
      'email': this.email,
    });
  }

}
github Nightapes / ngx-validators / examples / src / app / email-validator / reactive-form / email / reactive-form-email.component.ts View on Github external
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { EmailValidators } from 'ngx-validators';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-reactive-email',
  templateUrl: './reactive-form-email.component.html'
})
export class ReactiveFormEmailComponent implements OnInit {

  form: FormGroup;
  email = new FormControl('', Validators.compose([EmailValidators.normal]));
  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {
    this.form = this._fb.group({
      'email': this.email,
    });
  }

  addToForm(email) {
    this.form.get('email').setValue(email);
  }
}
github Nightapes / ngx-validators / examples / src / app / reactive-forms / phone-validator / phone-validator.component.ts View on Github external
templateUrl: './phone-validator.component.html',
  styleUrls: ['./phone-validator.component.css']
})
export class ReactiveFormPhoneValidatorComponent implements OnInit {
  form: FormGroup;
  countryCode: FormControl = new FormControl('', Validators.compose([
    Validators.required,
    PhoneValidators.isValidRegionCode
  ]));
  possiblePhone: FormControl = new FormControl('', Validators.compose([
    Validators.required,
    PhoneValidators.isPossibleNumberWithReason('ZZ')
  ]));
  phone: FormControl = new FormControl('', Validators.compose([
    Validators.required,
    PhoneValidators.isPhoneNumber('ZZ')
  ]));


  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {

    this.form = this._fb.group({
      'possiblePhone': this.possiblePhone,
      'phone': this.phone,
      'countryCode': this.countryCode
    });

    this.countryCode.valueChanges.subscribe(data => {
      this.phone.setValidators(
        Validators.compose([
github Nightapes / ngx-validators / examples / src / app / reactive-forms / phone-validator / phone-validator.component.ts View on Github external
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-reactive-phone-validator',
  templateUrl: './phone-validator.component.html',
  styleUrls: ['./phone-validator.component.css']
})
export class ReactiveFormPhoneValidatorComponent implements OnInit {
  form: FormGroup;
  countryCode: FormControl = new FormControl('', Validators.compose([
    Validators.required,
    PhoneValidators.isValidRegionCode
  ]));
  possiblePhone: FormControl = new FormControl('', Validators.compose([
    Validators.required,
    PhoneValidators.isPossibleNumberWithReason('ZZ')
  ]));
  phone: FormControl = new FormControl('', Validators.compose([
    Validators.required,
    PhoneValidators.isPhoneNumber('ZZ')
  ]));


  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {

    this.form = this._fb.group({
      'possiblePhone': this.possiblePhone,
      'phone': this.phone,
      'countryCode': this.countryCode
    });
github Nightapes / ngx-validators / examples / src / app / reactive-forms / creditcard-validator / creditcard-validator.component.ts View on Github external
import { CreditCardValidators } from 'ngx-validators';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-reactive-creditcard-validator',
  templateUrl: './creditcard-validator.component.html',
  styleUrls: ['./creditcard-validator.component.css']
})
export class ReactiveFormCreditcardValidatorComponent implements OnInit {

  form: FormGroup;
  creditcard = new FormControl('', Validators.compose([CreditCardValidators.isCreditCard]));
  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {
    this.form = this._fb.group({
      'creditcard': this.creditcard,
    });
  }

}
github Nightapes / ngx-validators / examples / src / app / reactive-forms / password-validator / password-validator.component.ts View on Github external
import { PasswordValidators } from 'ngx-validators';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-reactive-password-validator',
  templateUrl: './password-validator.component.html',
  styleUrls: ['./password-validator.component.css']
})
export class ReactiveFormPasswordValidatorComponent implements OnInit {

  form: FormGroup;
  value: string;
  password = new FormControl('', Validators.compose([
    //Validators.required,
    PasswordValidators.repeatCharacterRegexRule(4),
    PasswordValidators.alphabeticalCharacterRule(1),
    PasswordValidators.digitCharacterRule(1),
    PasswordValidators.lowercaseCharacterRule(1),
    PasswordValidators.uppercaseCharacterRule(1),
    PasswordValidators.specialCharacterRule(1)
  ]));
  confirmPassword = new FormControl('');

  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {
    this.form = this._fb.group({
      'newPassword': this.password,
      'confirmPassword': this.confirmPassword
    });

    this.form.setValidators(PasswordValidators.mismatchedPasswords());
github Nightapes / ngx-validators / examples / src / app / reactive-forms / password-validator / password-validator.component.ts View on Github external
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-reactive-password-validator',
  templateUrl: './password-validator.component.html',
  styleUrls: ['./password-validator.component.css']
})
export class ReactiveFormPasswordValidatorComponent implements OnInit {

  form: FormGroup;
  value: string;
  password = new FormControl('', Validators.compose([
    //Validators.required,
    PasswordValidators.repeatCharacterRegexRule(4),
    PasswordValidators.alphabeticalCharacterRule(1),
    PasswordValidators.digitCharacterRule(1),
    PasswordValidators.lowercaseCharacterRule(1),
    PasswordValidators.uppercaseCharacterRule(1),
    PasswordValidators.specialCharacterRule(1)
  ]));
  confirmPassword = new FormControl('');

  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {
    this.form = this._fb.group({
      'newPassword': this.password,
      'confirmPassword': this.confirmPassword
    });

    this.form.setValidators(PasswordValidators.mismatchedPasswords());
  }
github Nightapes / ngx-validators / examples / src / app / reactive-forms / password-validator / password-validator.component.ts View on Github external
@Component({
  selector: 'app-reactive-password-validator',
  templateUrl: './password-validator.component.html',
  styleUrls: ['./password-validator.component.css']
})
export class ReactiveFormPasswordValidatorComponent implements OnInit {

  form: FormGroup;
  value: string;
  password = new FormControl('', Validators.compose([
    //Validators.required,
    PasswordValidators.repeatCharacterRegexRule(4),
    PasswordValidators.alphabeticalCharacterRule(1),
    PasswordValidators.digitCharacterRule(1),
    PasswordValidators.lowercaseCharacterRule(1),
    PasswordValidators.uppercaseCharacterRule(1),
    PasswordValidators.specialCharacterRule(1)
  ]));
  confirmPassword = new FormControl('');

  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {
    this.form = this._fb.group({
      'newPassword': this.password,
      'confirmPassword': this.confirmPassword
    });

    this.form.setValidators(PasswordValidators.mismatchedPasswords());
  }
github Nightapes / ngx-validators / examples / src / app / reactive-forms / password-validator / password-validator.component.ts View on Github external
ngOnInit() {
    this.form = this._fb.group({
      'newPassword': this.password,
      'confirmPassword': this.confirmPassword
    });

    this.form.setValidators(PasswordValidators.mismatchedPasswords());
  }
github Nightapes / ngx-validators / examples / src / app / reactive-forms / password-validator / password-validator.component.ts View on Github external
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { PasswordValidators } from 'ngx-validators';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-reactive-password-validator',
  templateUrl: './password-validator.component.html',
  styleUrls: ['./password-validator.component.css']
})
export class ReactiveFormPasswordValidatorComponent implements OnInit {

  form: FormGroup;
  value: string;
  password = new FormControl('', Validators.compose([
    //Validators.required,
    PasswordValidators.repeatCharacterRegexRule(4),
    PasswordValidators.alphabeticalCharacterRule(1),
    PasswordValidators.digitCharacterRule(1),
    PasswordValidators.lowercaseCharacterRule(1),
    PasswordValidators.uppercaseCharacterRule(1),
    PasswordValidators.specialCharacterRule(1)
  ]));
  confirmPassword = new FormControl('');

  constructor(protected _fb: FormBuilder) { }

  ngOnInit() {
    this.form = this._fb.group({
      'newPassword': this.password,
      'confirmPassword': this.confirmPassword
    });