Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to validate valid IP address format for field in the service catalog

Santoshi Parit
Giga Contributor

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.

 

1 ACCEPTED SOLUTION

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');


}
}

View solution in original post

13 REPLIES 13

Mark Roethof
Tera Patron
Tera Patron

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I've made an example for you. Also easy to apply on multiple places in your instance, again: No scripting!

Add a Regex once:

find_real_file.png

Connect the regex to your variable:

find_real_file.png

How the validation looks like:

find_real_file.png

 

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

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. 

🙂

Thank you Mark for this useful information for IP Address validation through "Regex" .

 

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader