我正在使用AngularJS进行表单验证,特别是比较两个值。我希望用户在继续之前确认他输入的一些数据。假设我有以下代码:
<p>
Email:<input type="email" name="email1" ng-model="emailReg">
Repeat Email:<input type="email" name="email2" ng-model="emailReg2">
<p>
然后我可以使用验证功能:
<span ng-show="registerForm.email1.$error.required">Required!</span>
<span ng-show="registerForm.email1.$error.email">Not valid email!</span>
<span ng-show="emailReg !== emailReg2">Emails have to match!</span> <-- see this line
registerForm.$valid将根据输入框中的文本正确响应,但我不知道如何在此验证中使用比较以强制要求在允许用户提交表单之前必须输入相同的电子邮件地址。
我希望能够找到一种不需要自定义指令的解决方案,但如果无法实现,则将处理它。 这里提供了一个解决类似问题的自定义指令答案。
感谢任何帮助,谢谢
ng-disabled="emailReg != emailReg2"
怎么样? - AlwaysALearner