- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2012 08:19 AM
I have been searching everywhere to see if anyone has created a custom variable type for IP Addresses. I have created a service request for adding IP Addresses to our Relay list, but would love to have the IP Address input box formatted so that mistypes can't be made. Has anyone out there set anything up like this before? I am just having trouble figuring out where to start! Thanks!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2017 06:53 AM
Hey Paul! Good searching on the community to find this old thread! I never got a chance to build one, but plenty of folks on the Internet have for IP address, phone number, credit card and more. A quick Google search landed me on a few options. Check out JimmyP's post on "jump to the next field". The big trick here is you will have to convert this to a format that is friendly to ServiceNow variables in order for it to work. There are also probably better ways to do this leveraging AngularJS given this post is from 2008!
HTML/Javascript jump to next field
More searching led me to some other interesting pages that have solutions like this:
ng-ip-address Instead of automatically jumping, it restricts the use from doing anything other than entering a valid IP address
JavaScript Automatically Move Cursor to Next Field When Textbox Full
https://www.google.com/search?q=javascript%20ip%20address%20cursor%20jump%20angularjs
This should lead you in the right direction. If you still struggle, let me know and I'll go a step further.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2012 08:29 AM
I would build this as a single line text plus Client Scripts for onChange and onSubmit. Something like this should get you started:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if(isLoading || newValue == '') {
return;
}
var validIpAddressRegex = /^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$/;
if(!validIpAddressRegex.test(newValue)) {
g_form.setValue('ip_variable', ''); //Change based on your variable's name
alert('You must enter a valid IP Address.');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2012 09:07 AM
Thanks! That worked out great! But now, of course I want to get fancy with it. Is there a way to put in an OnLoad script that would format the submit box so that it already has the periods in it, and will jump to the next space after you enter in 3 digits?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2012 03:24 PM
🙂
That sure would be a fun one to build. Technically, it is possible with JavaScript. If I get bored, have some downtime, or something I'd love to try to write it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 01:55 PM
Hey Tony, I know its been over 5 years, but have you given this little jewel and more consideration?
~Paul Porter