By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Network Mac Address validation

P: 60
Hi

Can anyone send javascript code to validate the
network mac address(eg. 02:41:6d:22:12:f1)
It accepts value from 00:00:00:00:00:00 to
ff:ff:ff:ff:ff:ff.

On keypress event of textbox , i need to allow characters
0 to 9 , a to f , and : (colon).

On Clicking save button , script function should check the
format for valid mac address.

Text box length should be 17.

Pls post your replies.
Thanks in advance
somaskarthic
Sep 8 '06 #1
Share this Question
Share on Google+
4 Replies


P: 60
Hi

Can anyone send javascript code to validate the
network mac address(eg. 02:41:6d:22:12:f1)
It accepts value from 00:00:00:00:00:00 to
ff:ff:ff:ff:ff:ff.

On keypress event of textbox , i need to allow characters
0 to 9 , a to f , and : (colon).

On Clicking save button , script function should check the
format for valid mac address.

Text box length should be 17.

Pls post your replies.
Thanks in advance
somaskarthic
Sep 8 '06 #2

dlite922
Expert 100+
P: 1,584
Hi

Can anyone send javascript code to validate the
network mac address(eg. 02:41:6d:22:12:f1)
It accepts value from 00:00:00:00:00:00 to
ff:ff:ff:ff:ff:ff.

On keypress event of textbox , i need to allow characters
0 to 9 , a to f , and : (colon).

On Clicking save button , script function should check the
format for valid mac address.

Text box length should be 17.

Pls post your replies.
Thanks in advance
somaskarthic
Here you go buddy...
Expand|Select|Wrap|Line Numbers
  1.  function isValidMacAddress(macAdd) 
  2.  {
  3.   var RegExPattern = /^[0-9a-fA-F:]+$/;
  4.  
  5.   if (!(macAdd.match(RegExPattern)) || macAdd.length != 17) 
  6.   {
  7.    alert("Invalid Media Access Control Address");
  8.   }
  9.   else
  10.   {
  11.    alert(macAdd + " is a valid Media Access Control Address");
  12.   }
  13.  }
  14.  
  15.  
  16.  
Jan 18 '08 #3

dlite922
Expert 100+
P: 1,584
sorry, that's JS, i don't know if you wanted that. but easily convertable to PHP.

See: preg_match
Jan 18 '08 #4

P: 1
3 standard (IEEE 802) formats:

* 0a:1b:3c:4d:5e:6f
* 0a-1b-3c-4d-5e-6f
* 0a1b.3c4d.5e6f



Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3.     teststr="0a:1b:3c:4d:5e:6f";
  4.  
  5.     regex=/^([0-9a-f]{2}([:-]|$)){6}$|([0-9a-f]{4}([.]|$)){3}$/i;
  6.  
  7.     if (regex.test(teststr)){
  8.         document.write("Valid mac address");
  9.     }
  10.     else{
  11.         document.write("Not a valid mac address");
  12.     }
  13.  
  14. </script>
  15.  
  16.  
Jul 16 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.