How to validate IP Address
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2016 10:52 PM
Hi Amit,
To validate IP address in catalog item you need to create onchange client script which will validate your ip address format.
You can use regular expression to validate the IP address format.
Hope it helps you.
Regards,
Swapnil
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2016 11:49 PM
Hi Amit,
As Swapnil mentions you can use a reg ex.
there is a regex here for IPv4
How should I validate the IP Address in below format?
and some help here for IPv6
Re: Is it possible to validate fields on a character basis?
Best Regards
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2016 12:18 AM
Hi Amit,
Sometime back i have done the same requirement, Please see the below code and do modification as you like, first i created a script include and called this onchange sync ajax call.
Iam sharing the validations i have done
IpValidationClientSide: function() { // This will use in Client Side
var ipAddWithDots = this.getParameter('sysparm_ip').toString();
var ipLength = ipAddWithDots.length();
if (ipLength> 16){ //this for maximum legth is 15 (235.235.235.235)
gs.log('This Script Include if loop is Executing:'+ipLength);
bool = false;.
return bool;
}
var iparray = ipAddWithDots.split('\\.');//(To split ip array with dots.
if(iparryLength != 4){ (if you split with dots length is 4)
bool = false;
return bool;
}
for( i = 0;i < iparryLength ; i++){ //check for it contains any alpha numeric or negative values
gs.log('AAAA:This Script Include get for loop is executing');
if (isNaN(iparray[i]) || Number(iparray[i])<0 || Number(iparray[i])>=256){
gs.log('AAAA:This for-if loop is executing');
bool = false;
return bool;
}
Then call the onchnage catalog client script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2016 12:31 AM
Add this in a client script
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);
}
alert("You have entered an invalid IP address!");
return (false);
ipaddress should contain the input value of IP entered by the user.