this.listingPrice = '1!00'; const pattern = new RegExp('^[+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\.?([0-9]{1,2})?)?$'); console.log(pattern.test(this.listingPrice));
=> returns true
I'm currently using this regular expression to evaluate currency USD. It works for the most part, however any character can work for the "." part of the currency. For instance, 1!00 returns true on the pattern evaluating the user input. Is there something I am doing wrong with the current regex?
https://stackoverflow.com/questions/67362485/currency-usd-regex-javascript-typescript May 03, 2021 at 09:15AM
没有评论:
发表评论