Validation Regex for Numbers and as well allows decimal values ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 11:01 PM
Hi,
I have a requirement to create a new regex validation for catalog variable or modify the OOTB "Number" to allow the decimal value also.
Need assistance to create a regex validation for number as well as decimal values
Thanks in Advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 09:50 AM
Hi @Aman_t
Here's the best advice you'll ever get regarding Regex: ask ChatGPT to solve it for you!
Regex is one of those things you typically don't use often, so even the best devs aften forget the details in between the times they need it. On the other hand, it's the type of challenge that's quick and easy to solve by asking ChatGPT.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 10:30 AM
Hi,
Although Simon is correct in getting help from ChatGPT, there are also people on the Community that likes regex questions. I'm one of them.. 😀
So... this validation should work for you, and also providing an example on how you can test if the validation works with your requirements.
var regexValidation = /^\d+([.]\d+)?$/; // first match one or more digits, then an optional dot as decimal separator, and then another set of one or more digits to match
var testString = '1234.3456';
if (testString.match(regexValidation)){
gs.info('Valid');
}
else{
gs.info('Invalid');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 02:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 06:10 AM
Hi,
Just skip the starting and ending "/".
These are needed when running a regex in a server side script, not when defining a catalog variable validation.