【发布时间】:2015-09-17 03:53:32
【问题描述】:
您能告诉我如何在 Angular js 中验证密码。实际上我的表单中有两个密码。一个是密码,另一个是确认密码。当两者相同时,它是有效的,否则表单是无效的。我应用验证对于最小长度和最大长度。但是如何将密码与角度 js 中确认的密码进行比较
http://codepen.io/anon/pen/bVpeeP
<div>
<input type="password" placeholder="password" ng-model="user.password" name="password" ng-minlength="2" ng-maxlength="5" required style="width: 300px;padding: 20px;margin-top: 50px">
<span ng-show="myform.password.$dirty &&myform.password.$error.required">Required</span>
<span ng-show="myform.password.$dirty && myform.password.$error.minlength">too short</span>
<span ng-show="myform.password.$dirty && myform.password.$error.maxlength">too Long</span>
</div>
<div>
<input type="password" placeholder="confirmed password" ng-model="user.confiredpassword" name="confiredpassword" ng-minlength="2" ng-maxlength="5" required style="width: 300px;padding: 20px;margin-top: 50px">
<span ng-show="myform.confiredpassword.$dirty && myform.confiredpassword.$error.required">Required</span>
<span ng-show="myform.confiredpassword.$dirty && myform.confiredpassword.$error.minlength">too short</span>
<span ng-show="myform.confiredpassword.$dirty && myform.confiredpassword.$error.maxlength">too Long</span>
</div>
如果两个密码不一样,那我需要显示错误吗? 谢谢
【问题讨论】:
-
哇......永远不要在谷歌上搜索这个。绝不!!!!
-
在此主题的任何网络搜索中都有两页不同的结果和代码示例。至少在来这里之前进行一点研究并发布问题要求某人为您编写代码。
标签: javascript angularjs validation angularjs-directive angularjs-scope