[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


MAC address format

Posted on 2007-09-28
Medium Priority
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
  • 2
LVL 23

Accepted Solution

Ajay-Singh earned 200 total points
ID: 19979209
add this first.
MyMAC = MyMAC.replace('-', ' ').replace(':', ' ').replaceAll("[ ]+", "");

Author Comment

ID: 19979296
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

ID: 19979310
Yes. after that line

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month19 days, 8 hours left to enroll

872 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