Can we make a single line text catalog variable to be entered in a specific format?

S_53
Kilo Guru

Hey snow folks,

I have a single line text catalog variable called 'Alert Frequency' and I want to force the users to enter a specific format in it.

I made the max length of it to 12 and I want it in the format of 30,15,7,5,1 (something like this) with only numbers and commas.

I am able to restrict it to enter only numbers and commas but user can enter something like 123123 which doesn't make sense. 

I need something like number,number,number..... as shown below

 

find_real_file.png

 

Any thoughts?

 

Thanks in advance! 

1 ACCEPTED SOLUTION

Abhishek Pidwa
Kilo Guru

Hello ,

 

So after digging a bit and modifying some of the regex patterns, I found a solution for you. basically you can copy paste this entire code in your catalog client script for that catalog variable:

 

This will check various edge cases like no alphabets, no comma at the end , no comma in the beginning, only numbers etc etc.

 

find_real_file.png

 

Happy coding. Make sure that you change the variable names accordingly and you are good to go !

 

find_real_file.png

 

find_real_file.png

 

find_real_file.png

find_real_file.png

find_real_file.png

 

Please mark this answer as correct if this helps to solve your problem.

 

Thanks

View solution in original post

5 REPLIES 5

Bharath40
Giga Guru

You need to use regex patterns using on change client script, I found some links as below check if that helps

https://stackoverflow.com/questions/33368539/regex-for-only-numbers-with-commas

https://www.regextester.com/98336

Abhishek Pidwa
Kilo Guru

Hello ,

 

So after digging a bit and modifying some of the regex patterns, I found a solution for you. basically you can copy paste this entire code in your catalog client script for that catalog variable:

 

This will check various edge cases like no alphabets, no comma at the end , no comma in the beginning, only numbers etc etc.

 

find_real_file.png

 

Happy coding. Make sure that you change the variable names accordingly and you are good to go !

 

find_real_file.png

 

find_real_file.png

 

find_real_file.png

find_real_file.png

find_real_file.png

 

Please mark this answer as correct if this helps to solve your problem.

 

Thanks

Thanks Abhishek, that works great. 

 

But it is not covering the scenario where if we enter something like 123123123

 

Can you please help. Thanks again!

Alright here you go. A much simplified version of the regex:

 

Replace the line of code with this one:

 

var pattern = /[0-9]+(,[0-9]+)+/;

 

And you will see a result like thsi :

find_real_file.png

 

I have also tested other edge cases and it is working as expected. Let me know if you still face any other issue.

 

Thanks