Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

mr18
Tera Guru

Hi Kranthi,

Try below onSubmit client script

function onSubmit() {
	
var ips = g_form.getValue('<field name of ip address>');

var ipList = ips.toString().split(/[ :;?!~,`"&|()<>{}\[\]\r\n/\\]+/);
var ipsLength = ipList.length;
var reg = /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
			
//Loop through ip address
for(i=0;i<ipsLength;i++){
				
if(!reg.test(ipList[i]))
					
				
{
					
g_form.showFieldMsg('<field name of ip address>','Please enter correct IP Address!','error');
return false;
}
else{
					
g_form.clearMessages();
g_form.hideFieldMsg('<field name of ip address>',true);
return true;
					
}
}
}
		

kranthi24
Giga Contributor

Not working.

 

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

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)