仅输入数字和一个点规则的输入文本

时间:2018-02-01 22:39:15

标签: input numbers

阿罗哈:)

我有这个输入:

<input type="text" name="title" maxlength="15" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" value="<?=$price ?>">

它只允许数字和一个DOT。 但问题是如何设置规则,因此只能在中间设置点,例如:1.2; 11.23; 1.4634634634; 1241245125.46 所以它不允许设置.0或1。 ???

1 个答案:

答案 0 :(得分:0)

试试这个\ d +。\ d + 顺便说一句。你可以在这里测试你的正则表达式:https://www.regexpal.com/