The CreatorCon Call for Content is officially open! Get started here.

How to validate ip range by using client script only without using any glideajex or server side script. Please help me with example script

kranthi24
Giga Contributor

1.Test is a single line text variable. for example if i enter any ip range value(0.1.1.1 -25.5.5.5). its check the range and validate it.

2.if i enter incorrect(fsdfasf-11.1.1.1) ,(300.299.1.0) populate alert msg(please give valid ip range)

find_real_file.png

1 ACCEPTED SOLUTION

kranthi24
Giga Contributor

I have written client script to validate Ip range using ip address(IPV4) regex.

 

I divided two  ip address as string  separated by "-";

stored srt1 and srt2 to values in  var a (used replace function to remove dots make it as a single string (a))

nd var b (used replace function to remove dots make it as a single string (b))

use if condition to compare first ip address (a) is not greater than or equal second ip address(b)

ex :if(a>=b)

View solution in original post

7 REPLIES 7

BALAJI40
Mega Sage

Hi,

Please check the script in the below thread,

How to validate valid IP address format for field in the service catalog - IT Service Management - Q...

 

if it is catalog, take the regex and place it in regex validation in type specifications.

Service Portal Catalog Items: Regex Field Validation [Madrid] - Developer Community - Article - Serv...

JagjeetSingh
Kilo Sage

1. Go to question_regex table and create new regular expression. I am assuming your range is (0.1.1.1 -25.5.5.5).

Use below regular expression:

^(0(\.1){2}\.([1-9]|[1-9]\d|[12]\d\d)|0\.1\.([2-9]|[1-9]\d|[12]\d\d)\.([1-9]?\d|[12]\d\d)|0\.([2-9]|[1-9]\d|[12]\d\d)(\.([1-9]?\d|[12]\d\d)){2}|25(\.5){2}\.[0-5]|25\.5\.[0-4]\.([1-9]?\d|[12]\d\d)|25\.[0-4](\.([1-9]?\d|[12]\d\d)){2}|([1-9]|1\d|2[0-4])(\.([1-9]?\d|[12]\d\d)){3})$

Set validation message as you like.

2. Then go to your variable. In "type specifications" tab > Validation Regex > Select the one you created.

 

Check and let me know if it works for you.

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023

Not working. it is validating only one address. 

 

requirement  valid iprange ( 1.1.1.1 -255.255.255.255 )

ip range((0-255) -(0-255))

 

incorrect ip address range(359.1.1.1 -255.255.255.555)

359 is greater than 255 and 555 is greater than 255

find_real_file.png

Hi,

Do you want to validate the IP address range and not the IP address?