【发布时间】:2018-05-29 20:44:19
【问题描述】:
我在我的 html 页面中使用输入类型数字,但我不想要 e 格式的数字。我正在尝试使用如下的正则表达式:
$scope.regexInteger = '^[0-9^e]*$';
并尝试使用 ng-messages 使其无效
<input type="number" maxlength="20" class="w3-input w3-border w3-round-large" ng-pattern="regexInteger" name = 'intVal' />
<div ng-messages='intVal' >
<div ng-message="pattern">Invalid Integer</div>
</div>
但我无法使用 ng-messages 使其无效。我想我没有通过正确的正则表达式。
请纠正我哪里出错了。
【问题讨论】:
-
试试这个正则表达式:
/[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/(source) -
创建一个只接受数字的自定义目录。
-
这个正则表达式不会阻止用户输入'e'。
-
您通过在组内添加
^e来尝试实现什么?我的猜测是你试图明确地说“不是字符'e'”,这是有道理的,但你已经通过[0-9]隐含地明白了这一点,它只是说只接受“0”和“之间的字符” 9",即只有数字字符。