i've a problem with my regex here my rules :
- authorize UPPERCASE
- Exclude lowercase and accent
authorize(edited) Exclude only thoses special caracters & ' ( ) . _
my regex is actually :
/^[A-Z][A-Z\s]*[^&'()._]$/i
that's almost all I need, but it accept for exemple
POTATOé
when it shouldn't
and it doesn't accept POTATOéé which is normal
if anyone has the solution it would be very helpful
CodePudding user response:
You have a couple of problems with your Regex:
- The character
^
inverts the selection of characters. You allow any character that does not match your allowed special characters - Currently, only one single special character at the end of the string is allowed.
- You are using the modifier
i
which stands for case insensitive. Therefore lowercase letters are also matched.
Assuming the string has to start with an uppercase letter, and can contain uppercase letters, spaces and the specified special characters, your resulting regex could look something like this:
/^[A-Z][A-Z\s&'()._]*$/
CodePudding user response:
Thank for your answer,
I made a mistake in my explanation, the characters mentioned are in fact not allowed, but all the others are.
so rules are
- Authorize UPPERCASE
- Exclude lowercase and accent
- Exclude only thoses special caracters & ' ( ) . _
(edit) :
I find the solution for thoses 3 rules(Thank Jeanot Zubler you help me so much)
the Regex for thoses 3 rules is :
^[A-Z][A-Z\s^&'()._]*$
but if anyone knows how to add all the extra alphabets in this regex it would help me