[英]ng-pattern not working when limiting to 24 characters with regex
We have the following input field and we want the error message to show when the user has inputted 25 characters. 我们具有以下输入字段,当用户输入25个字符时,我们希望显示错误消息。 However, it is only showing when the user has put in 26 characters.
但是,它仅在用户输入26个字符时显示。
Here is the input field. 这是输入字段。
Here is the RegEx: /^.{0,24}$/
I have also tried: ^.{0,24}$
下面是正则表达式:
/^.{0,24}$/
我也曾尝试: ^.{0,24}$
Why is this not working when the user hits 25 characters? 当用户输入25个字符时,为什么这不起作用? Also, we are using angular
1.3.10
if this helps. 另外,如果有帮助,我们将使用角度
1.3.10
。
It seems to be working, like it is highlighting input fields when it is not satisfying provided pattern in ng-pattern
. 它似乎正在工作,就像在不满足
ng-pattern
提供的模式时突出显示输入字段一样。 Also it gives error after 25
because it starts with 0
to 24
since it makes an field invalid when its you are entering 26
它还在
25
之后给出错误,因为它以0
到24
开头,因为当您输入26
时它会使字段无效
As you are just worried about to enter character till 25 length, I'd say Despite of ng-pattern
use ng-maxlength
attribute by specifying length in it. 由于您只是担心输入字符直到25个长度,因此我想说尽管是
ng-pattern
,但通过在其中指定长度来使用ng-maxlength
属性。
<input ng-model="myModel" ng-maxlength="25"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.