- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2019 02:56 PM
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
Any thoughts?
Thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2019 03:28 PM
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.
Happy coding. Make sure that you change the variable names accordingly and you are good to go !
Please mark this answer as correct if this helps to solve your problem.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2019 03:09 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2019 03:28 PM
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.
Happy coding. Make sure that you change the variable names accordingly and you are good to go !
Please mark this answer as correct if this helps to solve your problem.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 08:05 AM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 01:40 PM
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 :
I have also tested other edge cases and it is working as expected. Let me know if you still face any other issue.
Thanks