Validate IP Address format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 03:40 AM - edited 01-09-2024 03:43 AM
Hi,
Can someone please help me with IP address validation Regex, maximum length allowed is 30, should not accept special characters including( "/" and "-" ). Should allow '" , " to enter multiple IPs.
Valid IP address formats example
Single IP --> 10.1.1.10
Multiple IPs --> 10.0.0.10,10.0.0.11,10.0.0.12
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 05:44 AM
Hi try below code
(function executeRule(current, previous /*null when async*/) {
var ipAddresses = current.ip_addresses;
var ipRegex = /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(,\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})*)$/;
if (ipAddresses && ipAddresses.length <= 30 && ipRegex.test(ipAddresses)) {
gs.info('IP addresses are valid.');
} else {
gs.info('Invalid IP addresses format or length.');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 08:57 AM
Hi Harish
Thanks for responding!!
But it is not working as expected, I am trying to achieve it through client script but my client script does not allow ',' in case of multiple IP addresses
Valid IP address formats are as below...
Single IP --> 10.1.1.10
Multiple IPs --> 10.0.0.10,10.0.0.11,10.0.0.12