MAC Address Formatting

jevans
Kilo Contributor

I've seen some inquiries and information related to MAC address transformation/normalization, but I'm not exactly the best at regular expressions so I'm having trouble getting this to work.

My instance contains several forms (including the Incident form) which include fields for a MAC address. While most people separate pairs of hex characters with colons, I've seen other formatting (dashes, periods, etc), and generally we like to remove all special characters and display only 12 hexadecimal characters (we have several other systems which this works universally for).

I configured a transformation which includes 5 transforms to remove up to 5 colons. Not only is this tedious, but I'd have to set up transforms for other special characters that may be used, and repeat the process for the multiple forms we include MAC addresses on.

Is there a simpler way to have the system strip out all special characters, and confirm the remaining characters are all hexadecimal?

I believe the regular expression I'm looking for is the following, but I'm not sure how to best apply it:
/([0-9a-fA-F]{12})/i

1 ACCEPTED SOLUTION

Here is a simple client script friendly replace function that you could use instead:



var macString = "01 23:45F7.89-aB";
macString = macString.replace(/\W/gi,"");


This code example will remove any non-alphanumeric character from the string and return a variable with just the characters that matter for the MAC Address.


View solution in original post

5 REPLIES 5

So this works perfectly in my development instance, but this past weekend I transferred my recent update set from development to production and I'm getting an error message:

onChange script error: RangeError: Maximum call stack size exceeded. function onChange_incident_u_conflicting_mac_11(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') { return; } //Type appropriate comment here, and begin script below var macString = g_form.getValue('u_conflicting_mac'); macString = macString.replace(/\W/gi,""); g_form.setValue('u_conflicting_mac', macString); }

The odd part is that the script still works, but it brings up this error message when the MAC address field is modified.

I tried searching for this error on the community site, but haven't found any matches. I Googled it as well, but none of the results were relatively helpful. Especially since this script works perfectly on my development instance.

Any ideas what may be causing this to happen?