Posts Tagged ‘asp.net’

Displaying time in relative format

Thursday, August 28th, 2008

Many websites specially forum sites display time relative to the current time as “3 Hours 25 Minutes ago”, “30 Seconds ago” etc. In this post I will show a method using which we can convert datetime into descriptive relative time string.

The method takes 2 parameters 1. the time to process, 2. the time to which the output will be relative. Usually it is DateTime.UtcNow. There is also an overload which only takes the time to process where the second parameter defaults to DateTime.UtcNow. Let us see some sample output of this function.

(more…)

Validating username with RegularExpressionValidator

Sunday, August 10th, 2008

The asp.net validation controls enable us to quickly validate user inputs in a variety of ways. This post talks about using RegularExpressionValidator to validate username in a registration page. Often we want to limit the types of characters which can be allowed in the username. For this example, we would only allow the following characters. a to z, A to Z, 0 to 9. By using a Regular expression validator, not only we successfully validate the user input, we can also provide immediate response to the user regarding the correctness of the username entered. So, let’s delve into the code.

(more…)


© 2008 By Nirandas, All rights reserved.