string exp = @" ^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\. (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; string ipAddress = "127.0.0.1"; bool isMatch = Regex.IsMatch(ipAddress,exp);
Showing posts with label Regular Expressions. Show all posts
Showing posts with label Regular Expressions. Show all posts
Thursday, August 26, 2010
How to validate IP address using Regular expression
Monday, August 16, 2010
How to validate file type with FileUpload control in asp.net using RegularExpression validator
Please note when you check a file type, remember to check of all the combination of letters. Example .Pdf, PDF, pdf, pdF, etc.
Example: Validate any pdf file
Example: Validate any pdf file
<%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <script runat="server"> protected void Save(object sender, EventArgs e) { this.Page.Validate(); if (this.IsValid) { if (this.fuPdfFile.HasFile && this.fuPdfFile.PostedFile.ContentType.ToLower().Equals("application/pdf")) { } } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload runat="server" ID="fuPdfFile" /> <asp:RegularExpressionValidator runat="server" ID="rvafuPdfFile" ControlToValidate="fuPdfFile" ErrorMessage="Invalid File" ValidationExpression="^.*\.([p|P][d|D][f|F])$" /> </div> <asp:Button runat="server" ID="btnSave" OnClick="Save" Text="Save" /> </form> </body> </html>
Tuesday, August 10, 2010
How to validate password strength using regular expression
Please note: code being formatted for the demonstration purposes.
<asp:TextBox runat="server" ID="txtMediumPassword" /> <asp:RegularExpressionValidator runat="server" ErrorMessage="Password should contain minimum 7 non repetitive characters" ControlToValidate="txtMediumPassword" ID="RegularExpressionValidator1" ValidationExpression="^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$" /> <asp:TextBox runat="server" ID="txtStrongPassword" /> <asp:RegularExpressionValidator runat="server" ErrorMessage=" Password should contain minimum 8 non repetitive characters, at least 1 Uppercase character, at least 1 lowercase character and at least 1 digit." ControlToValidate="txtStrongPassword" ID="regexPassword" ValidationExpression="^(?=.{8,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9])))(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).*$" />
Subscribe to:
Posts (Atom)
Azure Storage Account Types
Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...
-
Why we need asynchronous tasks? Execute a time consuming operations in parallel to the CLR thread which execute the request If you have ...
-
Demo: I was thinking a way to show images before actually uploading them to server. I would say to preview images using javascript. Obv...