How to validate IP Address
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2016 10:43 PM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2016 11:49 PM
Try any of the below options:
- var ipaddress = current.ip_address;
- function ValidateIPaddress(ipaddress)
- {
- 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))
- {
- return (true) //allow access
- }
- alert("You have entered an invalid IP address!")
- return (false) //deny access
- }
OR
- var ipAddress = current.ip_address;
- var ipAdressV4 = new SncIPAddressV4(ipAddress);
- var startIP = new SncIPAddressV4(IP Address Start);
- var endIP = new SncIPAddressV4e(IP Address End);
- var range = new SncIPRangeV4(startIP, endIP);
- if (range.contains(ipAdressV4))
- //allow access
- else
- //deny access
- }
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2018 12:04 PM
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)