如何檢測-1 o任何正整數?我試過^(\-1)|(?!\-)\d+$
,但不適合我。除了爲-1此匹配以及爲小於-1的所有號碼=> -2,-11,-1534,...不工作正則表達式-1或正整數的檢測
正則表達式測試:regexr.com
正則表達式中Agularjs HTML形式使用:pluker
<form name="myForm">
<input type="text" name="myInput" ng-model="myData" ng-pattern="/^(\-1)|(?!\-)\d+$/">
<div ng-if="myForm.myInput.$error.pattern" style="color:red;">
Input does not match the regexp pattern!
</div>
</form>
這個表達式仍然是有效-1000 –
@ SimchaKhabinsky,不,不是。我更新了鏈接來檢查-1000,正如你所看到的,它不匹配 – ndn