【发布时间】:2013-11-26 11:43:45
【问题描述】:
我需要使用模式匹配验证密码字段。我为此使用了 ng-pattern。但它不能正常工作。
我在这里给出的模式是,文本至少应包含 8 个字符,包括符号、字母和数字。但是当我输入任何字符串时,模式匹配就会变为真。
见以下代码
<body ng-controller="MainCtrl">
<form name="form">
<input type="text" name="password" ng-model="user.password" ng-pattern="/(^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[\W]).*$)/">
<input type="submit">
{{form.password.$error}}
</form>
</body>
我在这里错过了什么?
【问题讨论】:
-
你应该在问题中显示代码
-
我给了一个 pluker 链接。它包含代码。