Regex Validation

Ajith A Pillai
Tera Contributor

Hi All,

 

I have a requirement that related to regex validation.

Use Case: we have a catalog item which consists of couple of fields. One of the field is user id which is set as a string field. If user enters user id as only characters or only numbers it should allow to submit the request. 

It should be only one character and rest are numbers. This is the requirement.

 

Is there any way to achieve this?. I have seen couple of articles related to this but nothing match with my requirement.

If anyone implemented such things please help me to achieve it.

 

Thanks in advance.

Ajith Pillai.

 

8 REPLIES 8

J Siva
Tera Sage

Hi Ajith,
Could you please share any sample user ids?
Regards,
Siva

Hi Siva,

 

Sharing some sample ids

 

1. C003546

2. C783379

3. C079840

Hi Ajith,
Based on your sample user ids, i've created one variable validation regex record and linked that to the catalog item variable of type single line text. The below regex will do the following validations,
1) User ID length should be 7

2) First character shoud be an alphabet and the remaining characters should be numbers

JSiva_0-1739792609898.png

Regex: ^[A-Za-z][0-9]{6}$


Regards,
Siva

Renat Akhmedov
Tera Contributor

Hello Ajith,

Create the following record in the "question_regex" table, and in the variable settings "Type Specifications" tab, please use your newly created record,

You can achieve this requirement using a regular expression (regex) to enforce the format where the first character is a letter, followed by only numbers. The appropriate regex pattern for this validation would be:

^[A-Za-z][0-9]+$

 

Explanation:

^ ensures the match starts from the beginning.
[A-Za-z] ensures that the first character is an uppercase or lowercase letter.
[0-9]+ ensures that the remaining characters are one or more digits.
$ ensures the match ends after the numbers.

 

I hope this helps! Let me know if you need any further assistance, also don't forget to tap this as a correct answer if it really helped you,

Best regards,
Renat Akhmedov