MAC address format

I want my input MAC address (always 12 charators) as the following

1. xx:xx:xx:xx:xx:xx ( separated with : )
2. xx-xx-xx-xx-xx-xx ( separated with - )
3. xx.xx.xx.xx.xx.xx ( separated with . )
4. xxxxxxxxxxxx ( no separated  )
5. xxxxxxxxxx-xx ( last two charators separated with -)

The output always is  xx:xx:xx:xx:xx:xx ( separated with : )

Here is my code

in my jsp file

<input id="txtMAC" type="text" name="MACAddress" size="17"  maxlength="25" onchange="toggleVisibility(2);">
            <br>

in my java file


     MyMAC = MyMAC.replaceAll("(\\w{2})", "$1:");
     MyMAC = MyMAC.substring(0, MyMAC.length() - 1);
     

I want to know how I edit my code so that the jsp accept the input format but the output always xx:xx:xx:xx:xx:xx ( separated with : )
wasabi3689Asked:
Who is Participating?
 
Ajay-SinghConnect With a Mentor Commented:
add this first.
 
MyMAC = MyMAC.replace('-', ' ').replace(':', ' ').replaceAll("[ ]+", "");
0
 
wasabi3689Author Commented:
Do I still need my these two lines?


     MyMAC = MyMAC.replaceAll("(\\w{2})", "$1:");
     MyMAC = MyMAC.substring(0, MyMAC.length() - 1);
0
 
Ajay-SinghCommented:
Yes. after that line
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.