【发布时间】:2014-08-20 10:34:10
【问题描述】:
我有 html 文件:
<form role="form" ng-submit="resetPasswordRequest();" name="resetPasswordForm" novalidate>
<div ng-show="!sessionExpired">
<input type="password" ng-model="password" ng-focus placeholder="New Password" name ="password" autofocus ng-minlength="5" ng-maxlength="20" required />
<span ng-show="resetPasswordForm.password.$error.required && submitted">New Password Required</span><br>
<span ng-show="resetPasswordForm.password.$error.minlength">New Password should contain at least 5 characters </span><br>
<span ng-show="resetPasswordForm.password.$error.maxlength">New Password maximum length up to 20 characters only </span><br>
<input type="password" ng-model="resetPassword" ng-focus placeholder="Retype Password" name ="resetPassword" id ="resetPassword" autofocus required/>
<span ng-show="resetPasswordForm.resetPassword.$error.required && submitted">Retype Password Required</span><br>
<span ng-show="!resetPasswordForm.resetPassword.$error.required && resetPassword != password && submitted">Password not matching</span><br>
<br><button type="submit" class="login-btn" ng-click="submitted=true">SUBMIT</button><br>
</div>
<div ng-show="sessionExpired">
<p class="txt-bld error-message" >URL Expired</p>
</div>
</form>
我有控制器:
$scope.resetPasswordRequest = function(){
//valid form submission only process the logic
if($scope.resetPasswordForm.$valid){ //some logic }
}
使用上面的表单我可以验证表单密码字段 minlength,maxlenth,empty,但是密码和重新输入密码数据匹配大小写的问题。
<span ng-show="!resetPasswordForm.resetPassword.$error.required && resetPassword != password && submitted">Password not matching</span>
即使通过密码和重新输入密码的数据不匹配表单提交并调用控制器功能并处理控制器逻辑。 但是,如果表单中缺少任何验证,则重新输入和密码数据匹配情况正在工作,如果没有验证(最小,最大长度,空)没有发生(表格中的所有内容都是正例)密码并重新输入密码数据匹配不起作用。
如果没有外部指令,我如何验证表单密码并重新键入匹配最小长度、最大长度属性的密码数据。
【问题讨论】:
-
感谢您的建议,我想验证密码并在没有指令的情况下重新输入密码。
-
用指令来做是正确的方法。任何其他方式都容易出现问题。
标签: html angularjs forms validation