validating IP address URL in catalog variable

Amit Dey1
Tera Contributor

Hi I have a requirement to validate this type of IP address in catalog variable , example - http://10.68.6.238 , so which regular expression to use for this 

1 ACCEPTED SOLUTION

Yes, try this

var reipurl = /^https?:\/\/(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/;

View solution in original post

8 REPLIES 8

The issue is your else if-statement. You are checking "if the first regex doesn't match, OR if the second regex doesn't match". Meaning if one of them does match, the condition is still evaluated to true, and you consider the URL invalid.

Change the else if-statement to check "if the first regex doesn't match, AND if the second regex doesn't match", this will give you the result you are looking for.

 

else if ((!re.test(fieldValue) && !reipurl.test(fieldValue)) && (fieldValue != '')) {
    g_form.showErrorBox(fieldName, "Please enter valid URL");
    fieldValuefields.push(g_form.getLabelOf(fieldName));
    isValid = false;
} 

 

Hi , sorry my bad it worked now , can you also provide that your regex can get https also I mean like now - http://10.68.6.238/ and also this https://10.68.6.238/  , thanks for helping me 🙂

Yes, try this

var reipurl = /^https?:\/\/(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/;

thanks for the help