Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Villanuevand/c30253371316b9897320dd7afabda40f to your computer and use it in GitHub Desktop.
Save Villanuevand/c30253371316b9897320dd7afabda40f to your computer and use it in GitHub Desktop.
Angular Form Validator Pattern: only letters and numbers
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'form',
templateUrl: './form.component.html',
styleUrls: ['./form.component.scss']
})
export class Form {
form: FormGroup;
constructor(private fb: FormBuilder) {
this.form = this.fb.group({
title: ['', [Validators.pattern('^[A-Za-z0-9ñÑáéíóúÁÉÍÓÚ ]+$')]
],
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment