Regex - Starts with specific text and ends with number on Change

piyushnector
Tera Contributor

Hello,

 

I am looking for a solution on below - 

 

There is a field in the catalog item in which the user should only allow to enter specific text (STARTS with "ADA") and ends with a number. No special symbol is allowed.

 

This should be an immediate response, if the pattern does not match we should be getting an error (popup) message.

 

Example Text: ADARegionCountry5004

 

Regards,

Piyush Kumar

1 ACCEPTED SOLUTION

Hi @piyushnector ,

 

To make the regular expression case-insensitive, you can add the "i" flag at the end of the regular expression pattern. This will allow it to match both uppercase and lowercase letters.

 

Update this line var pattern = /^ADA.*\d$/;  to  var pattern = /^ADA.*\d$/i;

 

Regards,

Shravan.

Please mark as helpful and correct solution

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

8 REPLIES 8

Hi @piyushnector ,

Below is the code snippet for your reference.

SaiShravan_0-1678118603586.png

---

SaiShravan_1-1678118681512.png

 

In the client script please change the "u_text_field" value to the variable name on which you want to validate.

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Thank you that works, but how can I ignore the case bcoz if user tried to fill it in lower case this will give error

Hi @piyushnector ,

 

To make the regular expression case-insensitive, you can add the "i" flag at the end of the regular expression pattern. This will allow it to match both uppercase and lowercase letters.

 

Update this line var pattern = /^ADA.*\d$/;  to  var pattern = /^ADA.*\d$/i;

 

Regards,

Shravan.

Please mark as helpful and correct solution

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

MonicaW
Tera Guru

What would  var pattern look like if you needed to require the characters "-SA" at the end?

I tried the following, but it doesn't work:

var pattern = /^.*\d-sa/i;