Skip to main content
Participant
August 17, 2018
Answered

Format MAC address field in form

  • August 17, 2018
  • 2 replies
  • 3387 views

I’m building a form that I need people to input there MAC address.  MAC Address is a fixed string of 12 characters with a colon in between each 2 characters.  How do I format a field that will automatically put the colon in as the person types the characters?

i was going to use the custom format category in the format tab.  Do you know a JavaScript that would do that?

This topic has been closed for replies.
Correct answer gkaiseril

The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six groups of two hexadecimal digits, separated by hyphens - or colons : so one needs to decide on the display format and provide a validation script that allows the entry of either separator character

The arbitrary mask allows special characters like "&", "?",  "<", "%" etc to be entered and not reported as invalid. This can be stopped by changing  the "X" to "O", the letter o, but it will not limit the alphabetical characters to a-f or A-F.

With the RegExp object provided within JavaScript, one can restrict each character position to specific characters or group of characters and even allows for a one of a group of characters for any position. So one can specify a range of numbers, a range of capitalized alphabetic characters, a range of lower case alphabetical characters, and special characters.

From PDF form field properties

Arbitrary Mask Changes the format category to Custom and makes another text field available, in which you can type a custom format. Use this option to specify which types of characters the user can enter in any given position, and how the data displays in the field.

A

Accepts only letters (A–Z, a-z).

X

Accepts spaces and most printable characters, including all characters available on a standard keyboard and ANSI characters in the ranges of 32–126 and 128–255.

O

The letter “O” accepts alphanumeric characters (A–Z, a-z, and 0–9).

9

Accepts only numeric characters (0–9).

For example, a mask setting of AAA--p#999 accepts the input BOE--p#767. A mask setting of OOOOO@XXX accepts the input vad12@3Up.

For the MAC address the allowable characters are the digits 0-9 and the upper or lower case alphabetical characters of A-F followed by either a  colon (":") or a dash ("-") which is repeated 5 times and then is just valid character pair at the end.

A possible validation script could be:

if(event.value !="" && /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]){2}$/.test(event.value) == false){

app.alert("Invalid MAC address entered " + event.value, 1, 0);

event.rc = false;

}

One could also add custom formatting and keystroke validation scripts.

2 replies

Inspiring
August 18, 2018

You might want to add a validation script to check if any invalid characters are entered, or not enough characters.

try67
Community Expert
Community Expert
August 18, 2018

The arbitrary mask will not allow the user to enter less characters than specified in it. It's all or nothing.

gkaiserilCorrect answer
Inspiring
August 19, 2018

The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six groups of two hexadecimal digits, separated by hyphens - or colons : so one needs to decide on the display format and provide a validation script that allows the entry of either separator character

The arbitrary mask allows special characters like "&", "?",  "<", "%" etc to be entered and not reported as invalid. This can be stopped by changing  the "X" to "O", the letter o, but it will not limit the alphabetical characters to a-f or A-F.

With the RegExp object provided within JavaScript, one can restrict each character position to specific characters or group of characters and even allows for a one of a group of characters for any position. So one can specify a range of numbers, a range of capitalized alphabetic characters, a range of lower case alphabetical characters, and special characters.

From PDF form field properties

Arbitrary Mask Changes the format category to Custom and makes another text field available, in which you can type a custom format. Use this option to specify which types of characters the user can enter in any given position, and how the data displays in the field.

A

Accepts only letters (A–Z, a-z).

X

Accepts spaces and most printable characters, including all characters available on a standard keyboard and ANSI characters in the ranges of 32–126 and 128–255.

O

The letter “O” accepts alphanumeric characters (A–Z, a-z, and 0–9).

9

Accepts only numeric characters (0–9).

For example, a mask setting of AAA--p#999 accepts the input BOE--p#767. A mask setting of OOOOO@XXX accepts the input vad12@3Up.

For the MAC address the allowable characters are the digits 0-9 and the upper or lower case alphabetical characters of A-F followed by either a  colon (":") or a dash ("-") which is repeated 5 times and then is just valid character pair at the end.

A possible validation script could be:

if(event.value !="" && /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]){2}$/.test(event.value) == false){

app.alert("Invalid MAC address entered " + event.value, 1, 0);

event.rc = false;

}

One could also add custom formatting and keystroke validation scripts.

try67
Community Expert
Community Expert
August 17, 2018

You don't need a script. Under the Format tab select Special, Arbitrary Mask, and then enter this as the mask to use:

XX-XX-XX-XX-XX-XX

BglitningAuthor
Participant
August 18, 2018

Wonderful, thank you!