in reply to Re^3: How to enter a MAC address
in thread How to enter a MAC address

I'm close. How do I validate my entry? I need either 1 or 2 hexadecimal characters. I've got 6 entry widgets, 1 per byte. Each treats it's contents as a string. I'm validating on focusout. So far none of my regex's has worked, the naive version was:
-validatecommand => sub{$_[0] =~ /\x/},
Gee, hung up on a regex. Whoodathunk? :)

I've got 1 other problem. The first entry widget doesn't have focus when it starts, I have to hit tab first. How do I fix this?

Replies are listed 'Best First'.
Re^5: How to enter a MAC address
by liverpole (Monsignor) on Feb 15, 2007 at 00:14 UTC
    Update:  After re-reading the documentation, I see that what I originally suggested is wrong.  \xnn matches "the character whose numeric value is nn", where "nn" is a pair of hex digits.

    I think that /\x/ will only guarantee you that you have 1 hex digit in your string, though won't work.  If you want to make sure there are exactly 2 hex digits, use something like:

    -validatecommand => sub{$_[0] =~ /^[0-9a-f]{2}$/i},

    The ^ matches the beginning of the line, the $ matches the end, and the {2} matches exactly 2 hex digits (0-9 or a-f).  The i at the end causes ignoring of case, of course.

    Check perlre if you need to read up on regexes.  Good luck!


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/