- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 12:12 AM
Hi All,
I am new in this enviornment,
My requirement is : I have one field name :IP address this can accept only this type of format XXX.XXX.XXX.XXX(12 Digit and 3 dots ).
I have tried to use the pattern in client script,Unable to understand how its work.
Many thanks in advance.
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 03:36 AM
Its working, Need to do few changes to get eaxct result , i have done some changes in this script
need to add ^ and $ to avoid starting and end point characters(ex:...12.12.12.12....)
g_form.clearValue('ip_address',''); :to clear the
Client script:
\\
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ans = g_form.getValue('ip_address');
var reg = /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
if(!reg.test(ans))
{
alert('Please enter correct IP Address');
g_form.clearValue('ip_address','');
// g_form.setValue('ip_address');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 12:23 AM
Hi there,
Have a look at an article I wrote about validating variables.
https://community.servicenow.com/community?id=community_article&sys_id=f5b8a988db057300d82ffb2439961...
No Client Scripting needed!
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 02:28 AM
I've made an example for you. Also easy to apply on multiple places in your instance, again: No scripting!
Add a Regex once:
Connect the regex to your variable:
How the validation looks like:
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 03:11 AM
Thanks you very much Mark !!!
But we are using London version we don't have this function in our instance, i have tried this in my personal instance its working perfectly.
🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2020 03:29 AM
Thank you Mark for this useful information for IP Address validation through "Regex" .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 12:57 AM
Hi Santoshi,
I have written a blog for IP address validation; take a look on that and let me know;
it should handle all the cases and scenarios
https://community.servicenow.com/community?id=community_blog&sys_id=9968c0cadbd6ff402be0a851ca961904
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader