How to customize a angular number input validation
By : user3532069
Date : March 29 2020, 07:55 AM
Hope that helps I am using a directive that validates number input boxes. I would like to change it to fit my needs. right now it allows me to enter numbers or text and throws the error message on button click. It also triggers the function. I would like it to instantly throw the error message when text is entered and I also would like to have the button disabled until both inputs are valid.
I hope this helps . Angular provide some Validators like required,maxLength.. but you can create your own Validator like this : Create a fonction (this one take your control value, check if it's between 0 and 100. If it's okay, it returns null, which means no problems, otherwise you return an object with valid to false)
angular 7 input number validation
By : thelazy1
Date : October 14 2020, 01:00 PM
I think the issue was by ths following , You can fix this by adding Validators of Angular, There is an existing one for Required: Angular Form Validation
let numericRegex = /^[a-zA-Z0-9]+$/;
let myNumeric = new FormControl('', [
Validators.pattern(numericRegex), // <-- Here's how you pass in the custom validator using regex.
[formControl]="myNumeric" required >
value is required.