- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 01:52 AM
Hi All,
I have a field for frequency in catalog item to update it in Custom Table.
This field should be 234.234 format. how can i restrict it in Client Script.
Below is my Client Script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 03:11 AM
Hi @karthik65 ,
Use below script, i have tested it, working fine. it will accept 3 digit before and after decimal. If you before digit can be anything then use :var reg = /^\d+\.\d{3}$/;
var reg = /^\d{3}\.\d{3}$/;
var ans = g_form.getValue('frequency_number_u');
if(!reg.test(ans))
{
alert('Please enter a valid value.');
g_form.clearValue('frequency_number_u');
}
-------------------------------------------------------------------------
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
11-19-2024 02:43 AM
Try this ...
// Regular expression to match the format "123.456"
var reg = /^\d+\.\d{3}$/;
var ans = g_form.getValue('frequency_number_u');
If my answer helped you in any way, then mark it as helpful or correct. This will help others finding a solution.
Thanks,
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 03:11 AM
Hi @karthik65 ,
Use below script, i have tested it, working fine. it will accept 3 digit before and after decimal. If you before digit can be anything then use :var reg = /^\d+\.\d{3}$/;
var reg = /^\d{3}\.\d{3}$/;
var ans = g_form.getValue('frequency_number_u');
if(!reg.test(ans))
{
alert('Please enter a valid value.');
g_form.clearValue('frequency_number_u');
}
-------------------------------------------------------------------------
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
11-19-2024 03:14 AM
If you want exactly 3 degits on either side of the . (dot)
Then you need to reuse the d{3}
Like:
/^\d{3}.\d{3}$/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 03:17 AM
@karthik65 ,
Please try by using below regex:
/^\d{3}\.\d{3}$/
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish