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 IP Address

Amit Kumar6
Tera Contributor

Hi,

I have requirement for validating the IP Address in Catalog item in the format (0-235).(0-235).(0-235).(0-235)

Kindly suggest me how can i achieve this.

Thanks

6 REPLIES 6

ashishgupta
Tera Expert

Try any of the below options:



  1. var ipaddress = current.ip_address;
  2. function ValidateIPaddress(ipaddress)    
  3. {  
  4. if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))  
  5.   {  
  6.       return (true) //allow access  
  7.   }  
  8. alert("You have entered an invalid IP address!")  
  9. return (false) //deny access
  10. }


OR


  1. var ipAddress = current.ip_address;
  2. var ipAdressV4 = new SncIPAddressV4(ipAddress);  
  3. var startIP = new SncIPAddressV4(IP Address Start);  
  4. var endIP = new SncIPAddressV4e(IP Address End);  
  5. var range = new SncIPRangeV4(startIP, endIP);  
  6. if (range.contains(ipAdressV4))    
  7. //allow access  
  8. else  
  9. //deny access  
  10. }

apparently, this no longer works:

 

Background message, type:error, message: Illegal access to constructor com.snc.commons.networks.IPRangeV4(com.snc.commons.networks.IPAddressV4,com.snc.commons.networks.IPAddressV4)