简体   繁体   中英

How to apply Multiple ng-pattern with or condition in input box

Condition first: /^([a-zA-Z]{5})(\\d{4})([a-zA-Z]{1})$/; Condition second : (/^([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 

This will work in your case.

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

Explaination: -

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM