09 May 2010

Regular Expression for Day Month Year

Hi All,

In every application generally we need some validation for the day,month and year. Like user should only allowed to input valid date value.

Generally I am using calender control for the date. However recently I need to use some text box instead of the calender control. So I have used following validation expression for validating day,month and year.

Validation Expression for Day
^((([1-9]?)|([1-2][0-9])?)|([3][0-1]?))$

Validation Expression for Month
^((([1-9]?)|([0][1-9])?)|([1][0-2]?))$

Validation Expression for Year
[0-9]{4}

You have to place three text box for a date input and place regular expression validator against each. So in the validation expression property of the regular expression validator , use the above mentioned expression to validate proper input of each.

Hope this small tip will be useful. :)

01 May 2010

Short cut for reusable code in toolbox in Visual Studio

Sometime we need some part of coding frequently in a single or multiple application. What we do in this situation ? Just copy the source code and paste it to the destination.

Now, Visual Studio have a great feature instead of copy-paste the source code. For saving the require code at the toolbox, you just need to follow below 3 simple steps.
  1. Select the code snippets
  2. Drag it to the toolbox --> General tab area
  3. Drop it!!

It is too simple process. Even you can rename the code snippet with the appropriate name also. for that you have to just right click the code snippet and click on the rename option.


Finally, you can use this code snippet in any area of the visual studio application by just drag and drop of the selected code snippet.

Hope this will help you. :)