سؤال

I need RegExp for username input to allow maximum 3 capital letters.

asdFasdFasdF - pass

FFFasd - pass

asdFFF - pass

aFFsdF - pass

asd - pass

FFFF - fail

asdFadsFFF - fail

You get what I want.

Please help as I am stuck with this for a long time.

I tried this (?=(.*?[A-Z]){0,3}) but fails and maybe I don't need lookahead.

هل كانت مفيدة؟

المحلول 2

For ASCII only, try this:

^([^A-Z]*[A-Z]?[^A-Z]*){0,3}$

For Unicode uppercase, try this:

^([^\p{Lu}]*\p{Lu}?[^\p{Lu}]*){0,3}$

نصائح أخرى

Use an anchored negative look ahead:

^(?!(.*?[A-Z]){4}).*$

See a live demo

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top