正则表达式表示带逗号的浮点数
Regex for float with comma
我需要验证一个输入,包含一个项目的价格。值可能是..
1.2
1.02
30,000
30,000.00
30000000
所以我需要正则表达式来支持这一点。
这应该有效
/^[0-9]{1,3}(?:',[0-9]{3})*(?:'.[0-9]{1,2})?$/
想出了这个:
^'d+([',]'d+)*(['.]'d+)?$
用于检测它是否是价格的正则表达式。将其分解为多个部分:
^ # start of string
'd+ # this matches at least 1 digit (and is greedy; it matches as many as possible)
( # start of capturing group
[',] # matcher group with an escaped comma inside
'd+ # same thing as above; matches at least 1 digit and as many as possible
)* # end of capturing group, which is repeated 0 or more times
# this allows prices with and without commas.
( # start of capturing group
['.] # matcher group with an escaped fullstop inside
'd+ # same thing; refer to above
)? # end of capturing group, which is optional.
# this allows a decimal to be optional
$ # end of string
我建议您在创建正则表达式时尝试 http://regex101.com。
这应该有效
^(?:[1-9]'d*|0)?(?:'.'d+)?$
相关文章:
- 将浮点数排序为自然数
- 使用javascript从字符串中提取浮点数
- 为大型地理位置的坐标生成浮点数
- 如何使用Javascript使浮点数的精度相同
- 从字符串到浮点数的奇怪转换
- 如何将浮点数格式化为两位数
- 浮点数的总和在 JavaScript 中没有给出小数
- 如何使用 javascript 将浮点数格式化为十进制数(7)
- HTML浮点数字字段具有高精度,但呈现四舍五入值
- 使用浮点数获取基于数组的y轴最大/最小值
- 只允许带有退格和左右箭头的浮点数
- javascript正则表达式浮点数,以字符串结尾
- 在AngularJS中格式化浮点数而不丢失精度
- 如何通过 javascript 在浮点数中保留小数点数后的 2 位数字
- 在Javascript中,大浮点数的小数位数有限制吗
- 正则表达式用于逗号分隔浮点数的列表
- 正则表达式表示带逗号的浮点数
- RegExp 表示 JavaScript 中的浮点数,带有可选的(多个)逗号和小数点
- RegEx表示,对于浮点数(JavaScript),我的所有输入都为假
- 什么位模式表示双精度浮点数的最大值?