I want to validate a mobile number using Angular 4 and it should not accept any characters other than numbers up to just 10 digits.
Below is my code ,
<input type="text" formControlName="mobileNo" minlength=10 maxlength=10>
I want to validate a mobile number using Angular 4 and it should not accept any characters other than numbers up to just 10 digits.
Below is my code ,
<input type="text" formControlName="mobileNo" minlength=10 maxlength=10>
We can use pattern to validate mobile number in angular.
In typescript I check whether form is valid or not and sent error message
try this code...... typescript code ..
html code..
just add validators pattern
and the type will be number and it will avoid accepting any character
The keyPress event worked for chrome however does not work for Firefox. In chrome key presses like backspace and arrow key events are ignored by default and does not run the function however in Firefox it runs and these do not work. I added a small line
if (event.charCode !== 0)