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 03:49 AM - edited 01-09-2024 03:50 AM
Check this out
Validate IP Address Using Regex : A Great use of... - ServiceNow Community
You can put the multiple IPs in an array and validate it as shown in the Blog by Gunjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 04:48 AM
did you try this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 08:58 AM
Hi Anurag,
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 09:04 AM
Try this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ipAddresses = g_form.getValue('enter_ip_addresses')
var ipList = ipAddresses.split(',');
var ipRegex = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
for (var i = 0; i < ipList.length; i++) {
var ip = ipList[i];
if (ipRegEx.test(ip)) {
gs.info("Valid IP address: " + ip);
} else {
gs.warn("Invalid IP address: " + ip); // You can clear field and throw error here if neeed.
}
}
}