title: C# Regex Validating Mac Address
body: <p>I am trying to validate mac addresses. In this instance there is no <code>-</code> or <code>:</code> for example a valid mac would be either:</p>
  
  <pre><code>0000000000
  00-00-00-00-00-00
  00:00:00:00:00:00
  </code></pre>
  
  <p>However I keep getting false when run against the below code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Text.RegularExpressions;
  
  namespace parsingxml
  {
      class Program
      {
          static void Main(string[] args)
          {
              Console.Write("Give me a mac address: ");
  
              string input = Console.ReadLine();
              input = input.Replace(" ", "").Replace(":","").Replace("-","");
  
              Regex r = new Regex("^([:xdigit:]){12}$");
  
  
              if (r.IsMatch(input))
              {
                  Console.Write("Valid Mac");
              }
              else
              {
                  Console.Write("Invalid Mac");
              }
              Console.Read();
          }
      }
  }
  </code></pre>
  
  <p>OUTPUT: Invalid Mac</p>