我有两种不同的情况。
情况1:
<md-input-container class="md-block">
<label>Client Email</label>
<input required type="email" name="clientEmail" ng-model="project.clientEmail" minlength="10" maxlength="20" ng-pattern="/^.+@.+\..+$/" />
<div ng-messages="projectForm.clientEmail.$error" role="alert">
<div ng-message-exp="['required', 'minlength', 'maxlength', 'pattern']">
Your email must be between 10 and 20 characters long and look like an e-mail address.
</div>
</div>
</md-input-container>
在这里,对于所有类型的错误,我们都显示相同的消息。是否可以有多个消息并相应地显示它们。例如 - 当为空时{此字段是必需的。} 当用户开始输入时,直到少于 10 个字符 {最少 10 个字符是必需的。} 当字符长度超过 20 {允许最大 20 个字符}
案例二:
<md-input-container class="md-block">
<label>Password</label>
<input required type="password" name="password" ng-model="project.password" minlength="6" maxlength="8" ng-pattern="/^[0-9]{6-8}$/" />
<div ng-messages="projectForm.password.$error" role="alert">
<div ng-message-exp="['required', 'minlength', 'maxlength', 'pattern']">
Your password must be between 6 and 8 characters long.
</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>Repeat Password</label>
<input required type="password" name="password2" ng-model="project.password2" minlength="6" maxlength="8" ng-pattern="/^.+@.+\..+$/" />
<div ng-messages="projectForm.password2.$error" role="alert">
<div ng-message-exp="['required', 'minlength', 'maxlength', 'pattern']">
Your password must be between 6 and 8 characters long.
</div>
</div>
</md-input-container>
有什么办法可以将当前字段值与其他字段匹配。基本上这是用于密码和确认密码。我们将所有检查都放在密码字段中。在密码2中,我只需要检查它是否与密码相同并显示消息{确认密码与密码不同},直到两者都匹配。