如何在输入框中应用多个ng-pattern with或condition

时间:2016-07-26 10:35:07

标签: javascript angularjs

条件优先:/ ^([a-zA-Z] {5})(\ d {4})([a-zA-Z] {1})$ /; 条件第二:(/ ^([a-zA-Z]){4}([0-9]){5}([a-zA-Z]){1}?$ / g)

HTML

 <input type="text" ng-model="userDetail.id" name="uid" required="" ng-pattern="regx"  />


Angular 
scope.regx= Condition first or condition Second

scope.regx=/^([a-zA-Z]{5})(\d{4})([a-zA-Z]{1})$/ || /^([a-zA-Z]){4}([0-9]){5}([a-zA-Z]){1}?$/g;  not working 

1 个答案:

答案 0 :(得分:3)

这适用于您的情况。

/(?:(?=(^[a-zA-Z]{5}\d{4}[a-zA-Z]{1}$))|(?=(^[a-zA-Z]{4}[0-9]{5}[a-zA-Z]{1}?$)))/g

解释: -

enter image description here