Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate input number length with angular?

I want to validate a 9 digits number using angular,

this is in my modal :

<input type="number" class="form-control" ng-model="id" required>

i tried pattern = [0-9]{9}, seems its passing every number that its getting . I want to pass only number 000000000 - 9999999999 , min-max also not working for me.

this is what my app adding to this class:

 class="form-control ng-pristine ng-valid-number ng-invalid ng-invalid-required"

thank u !

like image 318
Elad Noty Avatar asked Nov 30 '14 11:11

Elad Noty


1 Answers

I just use a pattern as validator. The following code will make the field required and must be only digits of length 10

ngOnInit() {
    this.firstForm = this.fb.group({
        firstCtrl: ['', [Validators.pattern('^[0-9]{10}$'), Validators.required]],
    });
like image 93
Rami Alloush Avatar answered Oct 15 '22 02:10

Rami Alloush