MAC address format

Posted on 2007-09-28
Last Modified: 2008-09-01
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);">

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 : )
Question by:wasabi3689
    LVL 23

    Accepted Solution

    add this first.
    MyMAC = MyMAC.replace('-', ' ').replace(':', ' ').replaceAll("[ ]+", "");

    Author Comment

    Do I still need my these two lines?

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

    Expert Comment

    Yes. after that line

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    matchUp  challenge 9 52
    noX challenge 17 55
    How Complex Is This Java Course ? 9 52
    countAbc challenge 9 35
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now