Posts

Showing posts with the label Regular Expressions

ASP Regular expression to check length of textbox value

Hi, here is a regular expression validator in ASP which you can use to check if a certain textbox has less than a certain number of characters. <asp:regularexpressionvalidator runat="server" id="lengthRegex" controltovalidate="">" validationexpression=".{1,<n>}" errormessage="Please note that there should be less than <n> number of characters in the textbox"> </asp:regularexpressionvalidator> So, if you intend to make the textbox accept a number of characters in a range(say between 5 to 10) then the following changes would work <asp:regularexpressionvalidator runat="server" id="lengthRegex" controltovalidate="">" validationexpression=".{5,10}" errormessage="Please note that there should be between 5 to 10 characters in the textbox"</asp:regularexpressionvalidator> Suppose you need to limit the characters to only alphanumerics, then use the...

URL Regular Expression

Here is a good Regular Expression for evaluating a URL (http(s)?\:\/\/)?([\w_-]{2,}\.)+([\w_-]{2,})((\/)(\~)[\w_-]+)?((\/)[\w_-]+)*((\/)¦(\/)[\w_-]+\.[\w]{2,})?((\?[\w_-]+\=([^\#]+)){0,1}(\&[\w_-]+\=([^\#]+))*)?(#[\w_-]+)?

Dot NET Regular Expression

Hi, in this post, I will demonstrate how to use a Regular Expression using the Dot NET Framework. If you are new to Regular Expressions, this post would not be of much use. This is intended for an audience who knows regular expressions and need to implement a regular expression in their Dot NET code. There may be scenarios where you need to match a certain string with a Regular Expression. Using the Dot NET Framework, this becomes relatively easy. First, you need to import the namespace by defining using System.Text.RegularExpressions; Then, you can create a Regex object by calling its constructor. This is an overloaded constructor. I will show only one use of it. (You can explore the other!!!) Regex regularExpression = new Regex(" "); This would create a Regex object. Once created, you can call several methods to get the job done. I will show how the Replace method can be used to identify a character pattern and replace it with a character set of your own. (A good example i...