I have a simple html form containing regular text input. ng-minlength
, ng-maxlength
and ng-pattern
angular built-in form input directives are set on the input.
Problem: ng-pattern
check is applied before the length check by ng-minlength
and ng-maxlength
.
Question: how can I change the default check order: i.e. first check for the length, then apply pattern check?
Example:
<body ng-app>
<div>
<form name="myForm">
Name: <input name="name" type="text" ng-model="name" ng-minlength="3" ng-maxlength="16" ng-pattern="/^\w+$/"/>
<div ng-show="myForm.name.$dirty && myForm.name.$invalid">
<span ng-show="myForm.name.$error.pattern">Pattern error</span>
<span ng-show="myForm.name.$error.minlength || myForm.name.$error.maxlength">Length error</span>
</div>
<br/>
<input type="submit" value="Submit">
</form>
</div>
</body>
Current behavior:
- enter "#" - see "Pattern error"
- enter "###" - see "Pattern error"
Desired behavior:
- enter "#" - see "Length error"
- enter "###" - see "Pattern error"
FYI, related jsfiddle.
Thanks in advance.