Unable to see any changes on Incident Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
You are not seeing any change because the JavaScript is actually failing due to an invalid regular expression.
In your script, the ipRegex is written across multiple lines. JavaScript does not allow line breaks inside a regex literal, so the client script throws an error and stops executing. That is why the onSubmit logic never works.
Script
function onSubmit() {
var ip = g_form.getValue('ip_Address');
if (!ip) {
return true;
}
var ipRegex = /^(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]?)\.(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]?)$/;
if (!ipRegex.test(ip)) {
alert('Please enter a valid IP address like 192.168.1.1');
return false;
}
return true;
}*************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8m ago
Hi @neelamallik
@vaishali231 has given the working solution and corrected your script regex
Here is implementation without regex, I have tested as background script , you can check:
// Test values
var testIPs = [
'192.168.1.1',
'10.0.0.256',
'abc.def.1.1',
'172.16.0.1',
'1.1.1',
'255.255.255.255'
];
for (var i = 0; i < testIPs.length; i++) {
var ip = testIPs[i];
gs.info(ip + ' => ' + isValidIPv4(ip));
}
function isValidIPv4(ip) {
if (!ip) return false;
var parts = ip.split('.');
if (parts.length !== 4) return false;
for (var i = 0; i < parts.length; i++) {
var num = parseInt(parts[i], 10);
if (isNaN(num) || num < 0 || num > 255) {
return false;
}
}
return true;
}
Validation:
Thanks and Regards,
Mohammed Zakir
