- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 07:24 AM
Hi
I have to validate IP address and format should be like this 123.23.23.34
how can I validate it by using RegEx.
Thanks
Saurabh
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 08:50 AM
Hi Saurabh,
Following you can use and it works.
function validateIP(ip) {
//Check Format
var ip = ip.split(".");
if (ip.length != 4) {
return false;
}
//Check Numbers
for (var c = 0; c < 4; c++) {
//Perform Test
if ( ip[c] <= -1 || ip[c] > 255 ||
isNaN(parseFloat(ip[c])) ||
!isFinite(ip[c]) ||
ip[c].indexOf(" ") !== -1 ) {
return false;
}
}
return true;
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 08:50 AM
Hi Saurabh,
Following you can use and it works.
function validateIP(ip) {
//Check Format
var ip = ip.split(".");
if (ip.length != 4) {
return false;
}
//Check Numbers
for (var c = 0; c < 4; c++) {
//Perform Test
if ( ip[c] <= -1 || ip[c] > 255 ||
isNaN(parseFloat(ip[c])) ||
!isFinite(ip[c]) ||
ip[c].indexOf(" ") !== -1 ) {
return false;
}
}
return true;
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2019 04:09 AM
where do we have to put this code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 09:00 AM
This works for me. Try this:
var pattern = /^(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]?)$/;
if(!pattern.test(newValue) || (newValue.length<3) ){
alert("You have entered an invalid IP address!") ;
g_form.setValue('u_ip_address', '');
}
}
Source:https://www.w3resource.com/javascript/form/ip-address-validation.php
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 11:46 PM
Hi Saurabh,
Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader