【发布时间】:2018-07-02 14:49:53
【问题描述】:
我正在使用以下正则表达式:
var currentVal = $(this).val();
//making sure it's only numbers, decimals, and commas
var isValid = /^[0-9,.]*$/.test(currentVal);
我正在尝试修改它,使其也不允许使用空格。我尝试在正则表达式中添加 /s 但它仍然允许它。比较新的正则表达式,很快就会变得混乱
【问题讨论】:
-
所以你是说如果值中有空格,isValid 会返回 true?
-
您的正则表达式不应允许空格
-
正则表达式本身已经不允许使用空格:regex101.com/r/8q0hT5/1
-
在这里工作得很好jsfiddle.net/n57jwbuh
-
@executable 不,它应该启用点和逗号。
标签: javascript regex