All Apps and Add-ons

Sideview Utils: How to validate an IP address in the TextField module in Advanced XML?


Hi ,

I have an view written in advanced XML using Sideview Utils text field module. I want to validate an IP address in the text field. Is there any way that I can do this?


This has come up from time to time and the best way to do it is with a "customBehavior". There is a hidden docs page about customBehaviors - to read it go to "Tools > Other Tools", then scroll down to the other page to the bottom-most panel.


-- Since the specific implementation here uses Splunk's core messaging, you need to have a Message module in the view. Here I've included it right above to the TextField but you can put it anywhere on the page.

<module name="Message" layoutPanel="panel_row1_col1">
  <param name="filter">customValidator_1</param>
  <param name="maxSize">1</param>
  <param name="clearOnJobDispatch">True</param>

<module name="TextField" layoutPanel="panel_row1_col1">
      <param name="name">ip_address</param>
      <param name="label">IP</param>
      <param name="customBehavior">customInputValidation</param>

and then to define the actual customBehavior, the following Javascript has to go in $SPLUNK_HOME/etc/apps/YOUR_APP/appserver/static/application.js

if (typeof(Sideview)!="undefined") {
    Sideview.utils.declareCustomBehavior ("customInputValidation", function(textFieldModule) {
        var messenger = Splunk.Messenger.System.getInstance();
        textFieldModule.validate = function() {
            var v = this.input.val();
            return (/^(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(v));
        textFieldModule.onValidationFail = function() {
            messenger.send("info","customValidator_1", "You must enter a valid IP Address.");
        textFieldModule.onValidationPass = function() {

This example was quickly derived from a slightly different working example that ships with Sideview Utils, in case you wanted to look at that one too. You can navigate to that view by going to /en-US/app/sideview_utils/testcases_for_textfield.xml

0 Karma
Did you miss .conf21 Virtual?

Good news! The event's keynotes and many of its breakout sessions are now available online, and still totally FREE!