2021年3月31日星期三

Regular Expression for inputs in Reactive forms in Angular

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 with dollar and commas. However if they do this they will have to follow the US 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.

https://stackoverflow.com/questions/66898428/regular-expression-for-inputs-in-reactive-forms-in-angular April 01, 2021 at 12:27PM

没有评论:

发表评论