- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 05:24 AM - edited 08-23-2023 05:36 AM
Hi Everyone,
Need help in client script regex to allow only number form range 1 to 50000 in a single line text field.
Here is the regex I'm using and it is not working as expected. It allows till 50009. I want till 50000 only.
^(?:[1-9][0-9]?[0-9]?[0-9]?[0-9]?|1[1-5][0-9]?[0-9]?[0-9]?[0-9]?|2[0-4][0-9]?[0-9]?[0-9]?[0-9]?|25[0-5][0-9]?[0-9]?[0-9]?|6[0-4][0-9]?[0-9]?[0-9]?[0-9]?|50000)$
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 07:25 AM
This is working.
/^([1-9]|[1-9][0-9]|[1-9][0-9]{2}|[1-9][0-9]{3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65000)$/;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 05:52 AM - edited 08-23-2023 05:53 AM
I'm using it on a single line text variable and it is still allowing 50001 till 50009. I want till 50000 only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 05:59 AM
Hi @Saai1 Use the below script it was working
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var numericValue = parseInt(newValue, 10);
if (isNaN(numericValue) || numericValue < 1 || numericValue > 50000) {
g_form.setValue(control.name, oldValue);
alert('Please enter a number between 1 and 50000.');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 06:07 AM
It is not working on a catalog client script. Can you try on a single line text variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 06:07 AM - edited 08-23-2023 06:12 AM
Hi @Saai1 sorry for the confusion,
use the below code in on change client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var numericValue = parseInt(newValue, 10);
if (isNaN(numericValue) || numericValue < 1 || numericValue > 50000) {
if (newValue !== '') {
g_form.clearValue(control.name, true); // Clear the field value
g_form.showFieldMsg(control.name, 'Please enter a number between 1 and 50000.', 'error');
}
}
}
Please, Mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Eswar Chappa