我有以下货币验证模式。
/(?:^\d{1,3}(?:\.?\d{3})*(?:,\d{2})?$)|(?:^\d{1,3}(?:,?\d{3})*(?:\.\d{2})?$)/
验证:987,654,321.00
我需要一个模式来验证印度数字系统,例如
98,76,54,321.00
我想允许用户输入逗号和一个点。
我的条件很少。
- 我还应该允许用户输入逗号
- 金额不得超过 2 位小数。
- 金额应验证印度数字模式,即
98,76,54,321.00
,但不验证987,654,321.00
我引用了以下链接Duplicate但不满足我的要求。我需要帮助才能获得准确的模式 谢谢, 卡蒂克
最佳答案
基于示例和评论:
^(?:\d+|\d{1,2},(?:\d{2},)*\d{3})(?:\.\d{2})?$
Javascript 测试片段:
const reIndianCurry = /^(?:\d+|\d{1,2},(?:\d{2},)*\d{3})(?:\.\d{2})?$/;
console.log('-- Should Match:')
let arr = ['0.00', '123.00', '1,234.12', '12,34,56,789.00', '12,34,567', '123456', '12345.00'];
arr.forEach(function(s){console.log(reIndianCurry.test(s)+' : '+s)});
console.log('-- Should Not Match:')
arr = ['12,345,678.12', '12,34.00'];
arr.forEach(function(s){console.log(reIndianCurry.test(s)+' : '+s)});
关于javascript - 用于验证印度货币的正则表达式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51041096/