- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 11:47 PM
hi
i have one text field on service catalog item on which i have to do two validations:-
1. only accept ip address in their correct format
2. if more than 1 it should automatically insert comma
for eg. ip address1, ip adddress 2
and it should only allow comma for this no other characters.
thanks in advance!!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 12:35 AM
Then the following will validate the entry. I've named the field "ip_address".
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = /^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?: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]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/;
if (!pattern.test(newValue)) {
g_form.showFieldMsg("ip_address", "Invalid ip address. IP address should be delimited by a comma", "error");
}
}
Execution result:
Error because 2nd ip address delimited by ";"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 12:17 AM
Not clear about requirement 2. How will the user input ip addresses?
Will user enter multiple ip address separated by comma? In this case, user will be entering the comma and not the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 12:21 AM
yes user will enter comma if they use extra spaces or other special character it should not accept
eg:
1. ip_address1,ipaddress2,... - accepted
2. ip_address1 # ipaddress2 ip address3 - not accepted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 12:35 AM
Then the following will validate the entry. I've named the field "ip_address".
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = /^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?: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]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/;
if (!pattern.test(newValue)) {
g_form.showFieldMsg("ip_address", "Invalid ip address. IP address should be delimited by a comma", "error");
}
}
Execution result:
Error because 2nd ip address delimited by ";"