MAC Address Validation using Client Script and Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 03:53 AM
Hi
I have to validate MAC Address in CMDB using Client script and Business rule and format should be like this 00:0c:29:61:6d:37
how can I validate it by using RegEx.
Thanks,
Selvam Balakrishnan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 04:30 AM
Hi
You can use the below-provided regex to validate the MAC Address:
^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$
This regex will validate formats like "00:0c:29:61:6d:37" and "00-0c-29-61-6d-37".
Also, let me know if you need help with script.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 12:43 AM
Hi Kartik,
When we provide MAC Address value if format is incorrect then MAC Address field value should be cleared – Client Script
When MAC Address value is updated from Integration system if format is incorrect then MAC Address field value should be cleared and display the Error message - Business Rule
Can you please help me?
Thanks,
Selvam Balakrishnan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 03:23 AM
Wrote the client script and its working.
var special_pattern = new RegExp("^([0-9-A-Z-a-z]{2}):([0-9-A-Z-a-z]{2}):([0-9-A-Z-a-z]{2}):([0-9-A-Z-a-z]{2}):([0-9-A-Z-a-z]{2}):([0-9-A-Z-a-z]{2})$");
if(!special_pattern.test(newValue))
g_form.clearValue('mac_address');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 01:19 AM
Hi
For Client Script:
Ensure →
UI Type is All (to run of Native, Portal, and Agent Workspace)
Type is onChange
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var mac = g_form.getValue('<mac_address_field_name_goes_here>'),
macPattern = /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/i;
if(macPattern.test(mac)) {
//Valid MAC Address code goes here
} else {
//Invalid MAC Address code goes here
g_form.clearValue('<mac_address_field_name_goes_here>');
g_form.setMandatory('<mac_address_field_name_goes_here>', true);
}
}
For restricting Integration you can have a Business Rule (Data Policy is also an option😞
Ensure →
When: Before
Insert: True
Update: True
Filter Condition:
MAC Address is not empty
Script:
(function executeRule(current, previous /*null when async*/) {
var mac = current.getValue('<mac_address_field_name_goes_here>'),
macPattern = /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/i;
if(macPattern.test(mac)) {
//Valid MAC Address code goes here
} else {
//Invalid MAC Address code goes here
current.setValue('<mac_address_field_name_goes_here>', '');
gs.addErrorMessage('Provide correct MAC address');
}
})(current, previous);
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik