Regex to accept numbers and can only accept one dot for decimals.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:11 AM - edited 06-11-2024 11:38 AM
I am trying to write a regex with on change client and tried the below. It needs to accept numbers as below
ex: (should accept numbers and dots)
12345
12345.67
12345.678xxx (No limitation on decimals unless its not possible)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Accept numbers with only dots
var pattern = /^(([0-9.]?)*)+$/;
if (!pattern.test(newValue)) {
g_form.clearValue('u_amount');
g_form.showFieldMsg('u_amount', 'Accepted format : 354621.32', 'error', true);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:15 AM
@pardhiv What is the issue here, your regex is working accepting number and dot. Is it not working in client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:35 AM
It isn't accepting both the inputs I gave in the question. I don't have any limitation on number of decimal places. If there is no option , I can stick with 2 places

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:47 AM
@pardhiv I tested on my PDI and it is just working fine for me with both the inputs 1234 and 1234.12.
Please clear your cache of the browser and then check as the script is working just fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 08:14 PM
Seems like the Issue is with my client script , I tried multiple regex and they been clearing out values.