title: Angular2 restrict special characters in Template driven forms
body: <p>I want to restrict special characters in textbox.I mean if user enters any special characters they should not be displayed in the textbox.In Aangular 1  you can do that by using parsers. What is the best way to achieve that in Angular2.</p>
  
  <p><strong>Update</strong>
  In an attempt to achieve desired result I have come up with this.</p>
  
  <pre><code>input type="text" [(ngModel)]="user.name" #name="ngModel" #ctrlName     (onModelChange)="onChange('name')"
  
  onChange(field : string){
      this.user["field"] = this.user["field"].replace(/[^\w\s]/gi, '');
  }
  </code></pre>
  
  <p>but this was not updating the control value so I modified it like below</p>
  
  <pre><code>input type="text" [(ngModel)]="user.name" #name="ngModel" #ctrlName (onModelChange)="onChange('name',ctrlName)"
  
  onChange(field : string,ctrl : FormControl){
      var value = this.user["field"].replace(/[^\w\s]/gi, '');
      this.user["field"] = value;
      ctrl.value = value; 
  }
  </code></pre>
  
  <p>but now when I enter a special character it is removed from the input but if i test it for required field validity like name.valid , it results true which means that it is not removed from the model.Any help would be much appreciated.</p>