How to validate white spaces/empty spaces? [Angular 2]

前端 未结 18 2119
遇见更好的自我
遇见更好的自我 2020-12-04 19:14

I would like to avoid white spaces/empty spaces in my angular 2 form? Is it possible? How can this be done?

18条回答
  •  情歌与酒
    2020-12-04 19:43

    In your app.component.html

    First Name without space

    In your app.componen.ts file

    import { Validators, FormGroup, FormControl } from "@angular/forms";
    signupForm: FormGroup;
    ngOnInit(){
    this.signupForm = new FormGroup({
      name: new FormControl("", [
        Validators.required,
        Validators.pattern("^[a-zA-Z]+$"),
        Validators.minLength(3)
      ])
    })
    

提交回复
热议问题