简体   繁体   English

如何在输入框中使用或条件应用多个ng模式

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

Condition first: /^([a-zA-Z]{5})(\\d{4})([a-zA-Z]{1})$/; 先条件:/ ^([a-zA-Z] {5})(\\ d {4})([a-zA-Z] {1})$ /; Condition second : (/^([a-zA-Z]){4}([0-9]){5}([a-zA-Z]){1}?$/g) 条件秒:(/ ^([a-zA-Z]){4}([0-9]){5}([a-zA-Z]){1}?$ / g)

html 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: - 说明:-

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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