Network Mac Address validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • somaskarthic
    New Member
    • Aug 2006
    • 60

    Network Mac Address validation

    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
  • somaskarthic
    New Member
    • Aug 2006
    • 60

    #2
    Network Mac Address validation

    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

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Originally posted by somaskarthic
      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...
      Code:
       function isValidMacAddress(macAdd) 
       {
        var RegExPattern = /^[0-9a-fA-F:]+$/;
        
        if (!(macAdd.match(RegExPattern)) || macAdd.length != 17) 
        {
         alert("Invalid Media Access Control Address");
        }
        else
        {
         alert(macAdd + " is a valid Media Access Control Address");
        }
       }

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        sorry, that's JS, i don't know if you wanted that. but easily convertable to PHP.

        See: preg_match

        Comment

        • srenon
          New Member
          • Jul 2009
          • 1

          #5
          3 standard (IEEE 802) formats:

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



          Code:
          <script type="text/javascript">
          
          	teststr="0a:1b:3c:4d:5e:6f";
          	
          	regex=/^([0-9a-f]{2}([:-]|$)){6}$|([0-9a-f]{4}([.]|$)){3}$/i;
          	
          	if (regex.test(teststr)){
          		document.write("Valid mac address");
          	}
          	else{
          		document.write("Not a valid mac address");
          	}
          
          </script>

          Comment

          Working...