Skip to content

Instantly share code, notes, and snippets.

@nicobytes
Last active January 25, 2022 11:28
Show Gist options
  • Save nicobytes/3cb36c3725b3aa5ef5ede79098f166c5 to your computer and use it in GitHub Desktop.
Save nicobytes/3cb36c3725b3aa5ef5ede79098f166c5 to your computer and use it in GitHub Desktop.
64-angular-validations
<div class="field">
    <label class="label">Age</label>
    <div class="control">
      <input
        class="input"
        [class.is-danger]="form.get('age').dirty && form.get('age').invalid"
        type="text"
        formControlName="age"
      />
    </div>
    {{ form.get("age").errors | json }}
  </div>
this.form = this.formBuilder.group({
  age: [0, Validators.min(18)],
  price: [0, Validators.max(3000)],
  name: ['', [Validators.required, Validators.pattern(/^[a-zA-Z ]+$/)]],
  terms: ['', Validators.requiredTrue],
  email: ['', [Validators.required, Validators.email]],
  text: ['', [Validators.required, Validators.minLength(10), ...]],
  date: ['', Validators.required],
  category: ['', Validators.required],
  gender: ['', Validators.required],
});
^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment