[英]Regex to remove plus and minus sign of a number-type input using AngularJS
I'm trying to remove of my input type number every special character, and I also need that nobody be able to enter a minus (-) or plus (+) sign at the beginning and the end of the input.我正在尝试删除每个特殊字符的输入类型编号,并且我还需要没有人能够在输入的开头和结尾输入减号 (-) 或加号 (+)。
I'm using AngularJS.我正在使用 AngularJS。 I'll put the example code below.
我将把示例代码放在下面。
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">$</span>
<input class="form-control" tabindex="1" type="number" min="0"
step="0.01" ng-model="valorServicio" ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/"
name="valorServicio" required
/>
</div>
If someone know the answer I'd appreciate it.如果有人知道答案,我将不胜感激。
2 things to notice here.这里需要注意 2 件事。
First remove the slashes.首先删除斜线。 In
pattern
attribute you don't need to put the slashes at both side of the regex (ie /regex/
)在
pattern
属性中,您不需要将斜杠放在正则表达式的两侧(即/regex/
)
Second you need to wrap this input field in a form to use the browser pattern matching.其次,您需要将此输入字段包装在表单中以使用浏览器模式匹配。 Or you can also do it manually with js.
或者你也可以用js手动完成。
There is no other problem in your regex.您的正则表达式中没有其他问题。 That works fine
这很好用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.