我的表单有以下内联验证
delete threadPtr
但验证仅适用于<form name="coForm" novalidate>
<div>
<label>Transaction: </label>
<input type="text" name="transaction" class="form-control"
placeholder="<Direction> <Message Type>, ex.:OUT X12214"
ng-model="newco.transaction"
ng-pattern=/(^(IN )([A-Za-z0-9 &_]+))|(^(OUT )([A-Za-z0-9 &_]+))/
required>
<span style="color:red"
ng-show="coForm.transaction.$dirty ||
coForm.transaction.$invalid">
<span ng-show="coForm.transaction.$error.pattern">
Enter correct value for Transaction
</span>
<span ng-show="coForm.transaction.$error.required">
Transaction is required.
</span>
</div>
</form>
,而不适用于required
以下是积极匹配的几个例子:
pattern
答案 0 :(得分:1)
您错过了ng-pattern
属性&amp;的双引号你还没有在页面上初始化角度,你需要添加ng-app
以在页面上运行角度
<强>标记强>
<form name="coForm" novalidate ng-app="">
<div>
<label>Transaction:</label>
<input type="text" name="transaction" class="form-control" placeholder="<Direction> <Message Type>, ex.:OUT X12214" ng-model="newco.transaction"
ng-pattern="/(^(IN )([A-Za-z0-9 &_]+))|(^(OUT )([A-Za-z0-9 &_]+))/" required>
<span style="color:red" ng-show="coForm.transaction.$dirty || coForm.transaction.$invalid">
<span ng-show="coForm.transaction.$error.pattern">Enter correct value for Transaction</span>
<span ng-show="coForm.transaction.$error.required">Transaction is required.</span>
</span>
</div>
</form>
答案 1 :(得分:0)
Use &&
instead of ||
ng-show="coForm.transaction.$dirty &&
coForm.transaction.$invalid">