- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 05:56 AM
How we can add the validation for a variable to accept only numbers and '.'(dot).
Please suggest.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 06:00 AM
Hi @Archana23 ,
You can use catalog client script and use below script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Regular expression to allow only numbers and dots
var regex = /^[0-9.]*$/;
if (!regex.test(newValue)) {
g_form.showFieldMsg('variable_name', 'Only numbers and dots are allowed.', 'error');
g_form.setValue('variable_name', oldValue); // Revert to the old value
} else {
g_form.clearMessages(); // Clear any existing messages
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 06:03 AM - edited 12-12-2024 06:05 AM
Hi @Archana23 ,
You can try below regex
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var pattern = /^(([0-9.]?)*)+$/;
if (!pattern.test(newValue)) {
g_form.clearValue('u_amount');
g_form.showFieldMsg('u_amount', 'Accepted format : 354621.32', 'error', true);
}
}
var regex = (/^(([0-9.]?)*)+$/);
^[0-9 \.]+$g
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 06:00 AM
Hi @Archana23 ,
You can use catalog client script and use below script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Regular expression to allow only numbers and dots
var regex = /^[0-9.]*$/;
if (!regex.test(newValue)) {
g_form.showFieldMsg('variable_name', 'Only numbers and dots are allowed.', 'error');
g_form.setValue('variable_name', oldValue); // Revert to the old value
} else {
g_form.clearMessages(); // Clear any existing messages
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 06:03 AM - edited 12-12-2024 06:05 AM
Hi @Archana23 ,
You can try below regex
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var pattern = /^(([0-9.]?)*)+$/;
if (!pattern.test(newValue)) {
g_form.clearValue('u_amount');
g_form.showFieldMsg('u_amount', 'Accepted format : 354621.32', 'error', true);
}
}
var regex = (/^(([0-9.]?)*)+$/);
^[0-9 \.]+$g
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand