允许的金额字段 - 仅数字0-9,最多两位小数和$

时间:2015-03-16 18:47:33

标签: jquery html regex validation

您好
我有这个正则表达式,现在允许用户键入0-9位数字和最多2位小数。必须对此正则表达式进行哪些修改才能使其接受'$'。
[正则表达式的示例链接] [1]
正则表达式: this.value = this.value.replace(/ ^(\ d + \。?\ d?\ d?)?。* / g,'$ 1');

1 个答案:

答案 0 :(得分:0)

关注你的正则表达式:

^(\d+\.?\d?\d?)?.*

您必须添加\$符号,如下所示:

^(\$\d+\.?\d?\d?)?.*
  ^--- here, and escape the character

顺便说一句,如果你不想捕捉你可以做的dolar符号:

^(\$\d+\.?\d?\d?)?.*
相关问题