How to handle min number validation for French numbers in a reactive form?

Viewed 206

I am looking for solution to support the min value for the french numbers.

I do have form control where I added Validators.min function for the form control but when I start handling french numbers min function is not working.

Below is example.

 value: [
          { value: null},
          [Validators.required, Validators.min(0.01)],
        ],

enter image description here

1 Answers

The built-in Angular validators do not take into account the user/app locale:

https://github.com/angular/angular/issues/24099

So, you could write your own validator or pick one that is already there.

This article https://dev.to/ajayojha/decimal-number-validation-and-apply-the-currency-format-in-angular-3dbe explains how you can use @rxweb/reactive-form-validators to validate if a number is in the right numeric format, provided you have correctly set your app locale to the French one.

You can try to see if the minNumber validator from the same package does the job: https://docs.rxweb.io/form-validations/minNumber/validators

https://www.npmjs.com/package/@rxweb/reactive-form-validators#minnumber

Related