Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 11:13 PM
HI Team,
We have a requirement to validate a text field within the specified range from the other field in the form. Fr ex if the field "a" has a IP range of "192.168.1.0/24" , the other field "b" should be between 0-24 with a valid IP address. Ex: between 192.168.1.1 to 102.168.1.24
Please help in the script.
Thanks in advance,
Abhishek
Solved! Go to Solution.
Labels:
- Labels:
-
Scripting and Coding
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 02:02 AM
So it's not a CIDR.
It'll be much easier.
Create a regex like below for field "a"
^([01]?\d\d?|2[0-4]\d|25[0-5])(?:\.[01]?\d\d?|\.2[0-4]\d|\.25[0-5]){3}(\/([01]?\d\d?|2[0-4]\d|25[0-5]))$
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try {
var mask = g_form.getValue('a').split('/');
var end = mask[1];
var maskOctet = mask[0].split('.');
var endOctet = newValue.split('.');
for (var i=0; i<3; i++) {
if (maskOctet[i] != endOctet[i]) {
g_form.showFieldMsg('b', 'invalid ip address.', 'error');
return;
}
}
if (endOctet[3] < 1 || endOctet[3] > end) {
g_form.showFieldMsg('b', 'invalid ip address.', 'error');
}
} catch (e) {
alert(e.message);
}
}
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 04:13 AM
Thanks, Its working fine 🙂