Thursday 26 February 2015

Regular Expression to validate input text

Regular expression for Alpha numeric:

^[0-9a-zA-Z]+$


Regular expression for Alpha numeric with space:

^[0-9a-zA-Z ]+$


Regular expression for Alpha numeric with length:

^[0-9a-zA-Z]{5,} +$


Regular expression for Alpha numeric with single Quote and dot:

^[0-9a-zA-Z'.]+$

Regular expression for Email:

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Regular expression for For contact:

^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$

There are different format for Phone number. To Validate following:


  • (123) 456 7899
  • (123).456.7899
  • (123)-456-7899
  • 123-456-7899
  • 123 456 7899
  • 1234567899
use following expression:
'\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})'

Wednesday 25 February 2015

Abstract class in c#

An Abstract class is a class that provides a common definition to the subclasses and this is the type of class whose object is not created. 

A classes cannot initialize are called the abstract class. Abstract Classes are incomplete classes, means it will have both combination of implemented and unimplemented method with the properties, index, member, events and delegates. Use the abstract modifier in a class declaration to indicate that a class is made only to be a base class of other classes. We can declare any no of abstract methods in abstract class, but whenever you inherit this class into child class you must be implemented those abstract methods in your child class; otherwise complier gives an error in this case.

Why we use Abstract Class?

 The mail idea to have class as abstract is to provide the flexibility to derived classes to implement as per requirement. Abstract method does not provide an implementation and force to derived class to override this method.

When we use Abstract Class?

If you are creating something for objects that are closely related in a hierarchy, use an abstract class. Abstract classes allow you to provide default functionality for the derived classes. If you plan on updating this base class throughout the life of your program, it is best to allow that base class to be an abstract class. Why? Because you can make a change to it and all of the inheriting classes will now have this new functionality.

Rules of Abstract Class
  • Abstract classes are declared using the abstract keyword
  • We cannot create an object of an abstract class
  • If you want to use it then it must be inherited in a subclass
  • An Abstract class contains both abstract and non-abstract methods
  • The methods inside the abstract class can either have an implementation or no implementation
  • We can inherit two abstract classes; in this case the base class method implementation is optional
  • Methods inside the abstract class cannot be private
  • Abstract classes are useful when you need a class for the purpose of inheritance and polymorphism
  • The purpose of an abstract class is to provide default functionality to its subclasses
  • When a class contains at least one abstract method, then the class must be declared as an abstract class
  • It is mandatory to override the abstract method in the derived class.


Tuesday 10 February 2015

Eliminating Duplicates with DISTINCT

Eliminating Duplicates with DISTINCT 

The DISTINCT keyword eliminates duplicate rows from the results of a SELECT statement.

If DISTINCT is not specified, all rows are returned,including duplicates. 

ex. Result without DISTINCT


















Result with DISTINCT kwyword