find a location for property in a new city

Tuesday, 15 February 2011

Regex [x-y] range in reverse order

I started receiving a 'System.ArgumentException' error with a decription of 'parsing "[A-Za-z0-9_- %]+\.(bmp|jpg|jpeg|gif|png)" - [x-y] range in reverse order' after I wrote a C# Regex in my ASP.NET MVC web application.

I was using a RegularExpression Validator in my ASP.NET MVC app but it wasn't having any of it. I was looking at "A-Z" etc thinking IT IS THE RIGHT ORDER!

Turns out it is because I have a hyphen in another part of my regex expression. The one after the underscore.


Turns out hyphens have to appear at either the front or the end of the regular expression - or be escaped with a \. So now I have updated my regular expression from
[RegularExpression(@"[A-Za-z0-9_- %]+\.(bmp|jpg|jpeg|gif|png)")]
[RegularExpression(@"[A-Za-z0-9_ %-]+\.(bmp|jpg|jpeg|gif|png)")]

Follow britishdev on Twitter


  1. Thank you for posting this solution!

  2. Awesome. Exactly what I needed.

  3. Hannes

  4. Thank you. you saved my life


  5. Thanks for posting this useful content, Good to know about new things here, Let me share this, . Hadoop training in pune

  6. Replies
    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.

  7. Interesting post! This is really helpful for me. I like it! Thanks for sharing!

    Webseiten Gestaltung Lüdenscheid

  8. I found a lot of interesting information here. A really good post
    WebDesign Lüdenscheid

  9. I have gone through your blog, it was very much useful for me and because of your blog, and also I gained many unknown information, the way you have clearly explained is really fantastic. Kindly post more like this, Thank You.
    remote java developer jobs


  10. تنظيف منازل بالدمام تنظيف منازل بالدمام
    تنظيف منازل بالاحساء تنظيف منازل بالاحساء
    تنظيف منازل بمكة تنظيف منازل بمكة
    تنظيف منازل بجدة تنظيف منازل بجدة
    تنظيف منازل بالمدينة المنورة تنظيف منازل بالمدينة المنورة

    تنظيف بمكة شركة تنظيف بمكة بالبخار
    تنظيف بالمدينة المنورة تنظيف بالمدينة المنورة
    تنظيف بالجبيل افضل شركة تنظيف بالجبيل
    تنظيف بالدمام مؤسسة تنظيف بالدمام
    تنظيف بالخبر ارخص شركة تنظيف بالخبر