Can I "combine" 2 regex with a logic or? -


i need validate textbox input credit card number. have regex different credit cards:

  • visa: ^4[0-9]{12}(?:[0-9]{3})?$
  • mastercard: ^([51|52|53|54|55]{2})([0-9]{14})$
  • american express: ^3[47][0-9]{13}$

and many others.

the problem is, want validate using different regex based on different users. example: user1, visa , mastercard available, while user2, visa , american express available. generate final regex string dynamically, combining 1 or more regex string above, like:

user1regex = visa regex + "||" + mastercard regex  user2regex = visa regex + "||" + american express regex 

is there way that? thanks,

you did not state language whatever reason suspect it's javascript. var user1regex = new regexp('(' + visaregex + ")|(" + mastercardregex + ')'); can use (?:) speedier execution (non-capturing grouping) have omitted readibility.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -