- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2022 03:29 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 05:55 AM
Yes, try this
var reipurl = /^https?:\/\/(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 04:30 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 04:50 AM - edited ‎11-16-2022 04:51 AM
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 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 05:55 AM
Yes, try this
var reipurl = /^https?:\/\/(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 06:02 AM
thanks for the help