Tuesday, March 2, 2010

Sample regular expression - Numeric, Decimal, Alphanumeric, Date

Hi all,
Please find useful regular expressions for numeric, alphanumeric, alphabets only, date etc,
  1. Numbers only regular expression (0-9 regex) – ^[0-9]*$
  2. Decimal numbers with 2 floating point compulsory regular expression (0-9 with decimal) – ^([0-9]*)(\.[0-9]{2})?$
  3. Alphabets only regular expression () – ^[a-zA-Z]*$
  4. Alphanumeric string regular expression – ^[a-zA-Z0-9]*$
  5. Alphanumeric and white space regular expression – ^[a-zA-Z0-9 ]*$
  6. Date regular expression (dd/MM/yyyy regex) - ^(((0[1-9]|[12]\\d|3[01])\\/(0[13578]|1[02])\\/((19|[2-9]\\d)\\d{2}))|((0[1-9]|[12]\\d|30)\\/(0[13456789]|1[012])\\/((19|[2-9]\\d)\\d{2}))|((0[1-9]|1\\d|2[0-8])\\/02\\/((19|[2-9]\\d)\\d{2}))|(29\\/02\\/((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$
If you want to see how to build regular expressions you can see my article


  1. Thank you for sharing with good, useful survey. Nowadays mobile technologies are the most used in android development that needs in developing of mobile software apps for cells.

  2. that's simple and useful thanks....!!!!

  3. nice one really helpful

  4. Can Anyone tell me for this pattern


  5. [a-zA-Z]*[-][0-9]*
    Make * to your number of char required

  6. Not really helpful as many of the expressions are not working in c#
    for Example

    ^[a-zA-Z0-9 ]*$ this gives me nothing

    I am working in c# here is the code @"^([0-9]*)(\.[0-9]{2})?$" but all it gives me is blank when searching for decimal nos

  7. Expressions provided in the example are for validation. They are for single line value and should only match specified characters. If you want to search a decimal number from a random string you will need to remove ^ and $ sign. All the regex provided here has been checked with Regular Expression Validator.
    If you want to know why you are not able to search, provide your input.

  8. Nice Thanks a Lot !!!!


Comments posted on ASP.Net Ajax Tutorials Blog are moderated and will be approved only if they are on-topic and not abusive. Please email me or my team for tech-support or blogging related questions. Avoid including website URLs in your comments - Thanks Author