Archive for the ‘Regex’ Category

h1

Regex designer tool

November 4, 2008

 

If you want to design and test your regular expressions, you should find any power  utility. There is one – Free Regular Expression Designer.

 

Links

h1

Percentage Regex

November 3, 2008

If you need percentage regex for positive percent numbers, you can use this:

  • ^0?[0-9]{0,2}(\,[0-9]{1,2})?$|^(100)(\,[0]{1,2})?$

Valid values: 100; 13,1; 001; 002,11; 100; 000; 0

Invalid values:  15.1; 15,x; 101; -2; -0

 

 

h1

Global resources for validations (ASP .NET)

October 31, 2008

If you want to reuse expressions, error messages etc. for validators, you should use app.config storage or resources.

I will show you how to use resources for storing adjustments of ExpressionValidator .

  • Create Global resource directory

    1

  • Create GlobalResources – Call them ValidationResources.resx
    2 
  • Fill resources by expression and error message

    3

  • Add meta attribute  with resource resource name into your @Page directive on the page where you want to use resource.

    4

  • Add RegularExpressionValidator from toolbox and set it to resource values.

    5

  • If you want you can skip last step and you can set it in the designer

    6

  • Now run the application and look whats happening ;)

     7

h1

Regex – Date validator for DD.MM.YYYY fromat

October 31, 2008

 

This regex really works.  It is used for validation of DD.MM.YYYY, DD-MM-YYYY date format together with leap year computing.

 

(((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))

 

It validates: 10.10.2008, 29.02.2008, 29.02.2008, 2.2.2008, 2-2.2008, 2-2-2008, 30.04.00, 01.1.01

Doesn’t  validate: 29.2.2007, 30.00.00, 0.1.01

Links

Follow

Get every new post delivered to your Inbox.