我的形式有以下在線驗證NG模式不與正則表達式的工作
<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
下面是幾個例子正匹配:
OUT X12214
In X12850
IN ARRANT
OUT CORREC&TRANSLEG
OUT TEST_TEST
IN TEST2&TEST2
之前問問題請縮進你的代碼。 –