Regex in specific format

Hello! I need to collect a Id number in a specific format. Only allowed format is XXX-XXXXXXXX. Here, first 3 digits are alphanumeric, then one hyphen(-), then exactly 8 numeric digit. Some examples are:

  1. P57-23454128
  2. KAS-75455329
  3. PE3-41000755

Type of this question is text. I have tried regex formula in these way:

  1. regex(.,’^[0-9][A-Z]{3}[-]{1}[0-9]{8}$’)
  2. regex(.,’^[0-9][A-Z]{3}-[0-9]{8}$’)
    Unfortunately, none of them worked for me. I can’t find where I am doing wrong.
    Any suggestion please. Thanks in advance.

The correct one would be

regex(.,'^[0-9A-Z]{3}-[0-9]{8}$')

You can use https://regex101.com/ to create, validate and read about the syntax.

2 Likes

Hi ks_1,
Thanks a lot for your kind support. Yes, it worked for me now. Problem solved.

1 Like

Hello @tasfik_rukan ,
Also 000-00000000 or ZZZ-99999999 would be valid for the regex solution above. Is this Ok for you? Otherwise, the formula would need adaption for those invalid sequences…

Hi wroos,
Thanks for your reply. Yes, it would be good to know this too… Could you be a little bit of more specific about how to construct this formula that you mentioned? Thanks in advance again.

@tasfik_rukan, you should be able to learn more about regex through our support article Restricting Text Responses With Regular Expressions. Besides we also have a lot of examples in the community which should help you learn more on regex.