我在模板中的以下內容:的場角的驗證是有效的,但不是必需
<div class="form-group">
<label for="work_phone">Work Phone</label>
<input type="text"
class="form-control"
name="workPhone"
ng-class="{'borderRed': contactInformation.workPhone.$invalid && contactInformation.submitted}"
ng-model="controller.contactInformation.workPhone"
ng-pattern="/^\d+$/"
maxlength="10"
id="work_phone">
<small class="error"
ng-show="contactInformation.workPhone.$invalid && !contactInformation.workPhone.$pristine && contactInformation.submitted">
That's not a valid phone number (only numerics are allowed)!
</small>
</div>
條件:
如果該字段爲空/不變,形式應保持有效。
2.如果在該字段中有任何值,則應該根據ng-pattern
中提供的正則表達式進行驗證。
看起來很微不足道。我知道。但對於一些愚蠢的原因,無法找到一個解決方案
所以是它,如果NG-模式的輸入定義,這將是即使「需要」的部分被跳過有效性檢查? – beNerd