javascript - ng-pattern not working with regular expression -
my form has below inline validation
<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 transaction </span> <span ng-show="coform.transaction.$error.required"> transaction required. </span> </div> </form>
but validation works required
, not pattern
below few examples positive match:
out x12214 in x12850 in arrant out correc&transleg out test_test in test2&test2
you missing double quotes on of ng-pattern
attribute & have not initialize angular on page, need add ng-app
run angular on page
markup
<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 transaction</span> <span ng-show="coform.transaction.$error.required">transaction required.</span> </span> </div> </form>