I am using Angular 8 with reactive forms. Given a form input field where user inputs a value with or without currency. Example:
Enter Amount
[ Amount input field ]
I wanted to validate the input using Validators in reactive forms. For that, I need a regular expression
to validate the following 2 scenarios:
- The user has provided only
numbers
(0-9) . Example:
Enter Amount
[ 100009 ]
- The user has provided
numbers
withdollar
andcommas
. However if they do this they will have to follow theUS currency system
strictly. Example:
Enter Amount
[ $100,000 ] or [ $1,100,000 ] or [ $100 ] or [$1]
are acceptable whereas $,1000
$10,00
,,100
$$100
,$100
,$100$
,$,100
etc. are not.
Please note that the not acceptable cases
can be many more, as I have listed a few whatever came to my mind.
NOTE : Since I am using Angular, so if any pipe
modifications can be done, that would also suffice as long as the requirements are met.
没有评论:
发表评论