App input validation options?

I'm wondering how to validate the input provided to a string input like this:

input "esp32IpAddr", "text", title: "Esp32 IP Addr", submitOnChange: true, defaultValue: "192.168.1.123", required: true, noAutoComplete: false

I want to use something like this function to validate it for example:

public static boolean isIP(String str)
{
    try
    {
         String[] parts = str.split("\\.");
         if (parts.length != 4) return false;
         for (int i = 0; i < 4; ++i)
         {
             int p = Integer.parseInt(parts[i]);
             if (p > 255 || p < 0) return false;
         }
         return true;
    } catch (Exception e)
    {
        return false;
    }
} 

I was looking around here but didn't see anything.

There's nothing you can do "officially" in the UI that I can think of. But updated() is called when "Save Preferences" is clicked, so you could do some validation there and display an error message in the UI (on a dynamic page) or in Logs (pretty easy, even if not as intuitive for users) if your validation check fails then.

Take a look at this it may give you some ideas. My solution required using multiple pages.
https://raw.githubusercontent.com/arnbme/nyckelharpa/master/Nyckelharpa.groovy

ok, thanks for the ideas! I'll take a look

I was thinking of something similar to the "required" field that already exists and checks for an empty input may be running in a way that can be asked to run something in addition.

With submitOnChange = true, no need to wait for updated. Validation code can be called performed any time, tho performing validations in the code prior to page sometimes causes problems with settings variables or calls to parent. I like to perform validations to disabled app saving, then either do them again later, or save the results, to display an error message.