views:

149

answers:

1

Hi,

I need help with a constraint:

Constraints = new RouteValueDictionary(new { filename = @"" })

It has to be only numeric (no letters, slashes etc).

+4  A: 

I'm not sure I understood the question, but as far as I know, you can simply provide regular expressions in the Constraints dictionary.

I think there is even an example for that in the MSDN refguide:

reportRoute.Constraints = new RouteValueDictionary { 
  { "locale", "[a-z]{2}-[a-z]{2}" }, 
  { "year", @"\d{4}" } };

based on that, I think what you have to write:

Constraints = new RouteValueDictionary(new { filename = @"\d+" })
Gaspar Nagy
I think you're right, but you should probably use \d+ instead of \d* - the * allows no characters where the + requires at least one which is probably the intention.
Simon Steele
You are right. I did not wanted to go into the Regex details, but \d+ is definitely more defensive than \d*. I have changed it.
Gaspar Nagy