Posts

Showing posts from October, 2009

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_-]+)?

Java Sorting Arrays

Hi, All you Java folks must have faced a situation where you require to sort an array of custom objects using Java. Sorting a string array is easy with Java. But, what happens when you have a custom object array, say an array od Person objects to sort. You need to sort them according to a specific custom condition. With java interfaces, this becomes easily doable. In this example I will use the custom object as 'Car' public class Car { int age; string id; string color; } I need to sort them according to the age. Thus, according to the ascending order. First, you need to implemet Comparable interface of java. public class Car implements Comparable { int age; string id; string color; } So, add the above code in Red. This tells that this class implements the Comparable interface and accepts Car objects only. Now, you need to actually implement the methods regarding the interface. public int compareTo(Car o) You must implemen