Skip to content

Regular Expression Validation for MAC Addresses in ASP.NET

March 14, 2012

If you would like a custom regular expression for entering MAC Addresses inside a text box, you can easily do this using a RegularExpressionValidator ASP.NET control with the following code:-

<td>MAC Address</td>
<asp:RequiredFieldValidator id="rfvCustomMACAddress" CssClass="errorMsg" ControlToValidate="txtCustomMACAddress" ErrorMessage="MAC Address is required." Display="Dynamic" Width="100%" runat="server">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rgevCustomMACAddress" runat="server" CssClass="errorMsg" ControlToValidate="txtCustomMACAddress" ErrorMessage="MAC Address format is required." Display="Dynamic" Width="100%" ValidationExpression="^(?:(?'1'[0-9a-fA-F]{2})(?:\:)(?'2'[0-9a-fA-F]{2})(?:\:)(?'3'[0-9a-fA-F]{2})(?:\:)(?'4'[0-9a-fA-F]{2})(?:\:)(?'5'[0-9a-fA-F]{2})(?:\:)(?'6'[0-9a-fA-F]{2}))$|^(?:(?'1'[0-9a-fA-F]{2})(?:\-)(?'2'[0-9a-fA-F]{2})(?:\-)(?'3'[0-9a-fA-F]{2})(?:\-)(?'4'[0-9a-fA-F]{2})(?:\-)(?'5'[0-9a-fA-F]{2})(?:\-)(?'6'[0-9a-fA-F]{2}))$">*</asp:RegularExpressionValidator>
<th><asp:TextBox ID="txtCustomMACAddress" runat="server" Width="200px"></asp:TextBox></th>


This allows a regular expression validation on the client side of the ASP.NET page without the use of the code if(Page.IsValid).


From → Uncategorized

  1. Johnd131 permalink

    Hi! Someone in my Myspace group shared this website with us so I came to look it over. I’m definitely loving the information. I’m bookmarking and will be tweeting this to my followers! Great blog and terrific design and style. fecekgaacdcc

  2. Johne68 permalink

    I appreciate you sharing this article.Thanks Again. Really Cool. dddddecdedde

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: