How can I restrict a Letter

Dear Experts,

I want to restrict a word from Input.
For example,
Allow Input: 1001A0, 1002B1, 1003D3 etc (Allow input A-Z except for C)
Restrict Input: 1001C0

Thanks in Advanced

Welcome back to the community, @tanzilhuda! So, your requirement is something like a code where users are able to input the following:

  • 4 digit integer
  • Then a capital alphabet from A-Z (except C)
  • And another 1 digit integer

So the code should have a total of 6 characters (both integer and alphabets)?

Absolutely Yes. Would you help me with how can I write the code?

Should the first digit be 1 by default or could it be anything else?

Yes, first digit will be β€œ1” by default.

OK, this regex code should help you solve your issue:

regex(., '^[1][0-9]{3}[(A-B)|(D-Z)][0-9]{1}$')

For details, please feel free to visit our support article Restricting Text Responses With Regular Expressions.

1 Like

Dear BOSS,

It’s working amazingly. Thank you so much. But if I want to use β€œ^” what code will be?


Try using it inside the [ ] as [^] in one of the numbers.

I write this code: regex(., β€˜^[1][0-9]{3}[(A-Z)^C][1-9]{4}$’)

But it is not working. Would you help me how can I write the code using β€œ^”

OK, try using this regex code:

regex(., '^[1][0-9]{3}[^C][1-9]{4}$')

I write your code: regex(., β€˜^[1][0-9]{3}[^C][1-9]{1}$’)
It is working amazingly. Thank you so much.

1 Like

Beware that:

  • [^C] allows any character not being β€œC”, including β€œc”, and not only letters. So I don’t think it applies here.
  • [(A-Z)^C] means β€œany character being between A and Z or not being C”. I think what you want is β€œand”.

So if I am not mistaken, the right formula is the first that @Kal_Lam suggested, or this simplified variant: