I'm trying to create a Regular Expression to only accept "/Controller/Action" strings and I came upt with this:
"/[^a-zA-Z0-9]/[^a-zA-Z0-9]"
Now, when the code runs it throws a FormatException saying "Input string was not in a correct format." My string at this point is coming in empty. How can I only check once the property has a value or after trying to submit?
I think your regular expression is wrong. You put the ^ symbol at the beginning of the [. Doyou know it negates? This meand that no char in the square bracke will be accepted. So probably you have to remove it. Moreover you have to put some repetition char,
that say that the gropu may repeat several times. I think you hae to substitute each [^a-zA-Z0-9] with [a-zA-Z0-9]+
Also this way it is not...perfectly correct since controller names cannot start with a digit...first chat cannot be a digit. Moreover they can contain an underscore too...
I'm trying this and I'm still receiving the same exception: @"^/([A-Za-z]+)/([\w]+)$". Now when my action is called, it returns the property with @"/Controller/Action" instead of blank so that's not solving it either. The exception appears when the View
is called and the model trying to show the editor for my property.
Can you tell me what is wrong with my regular expression?
humble-appre...
Member
32 Points
73 Posts
Regular Expression for Controller and Action
Mar 27, 2012 01:20 PM|LINK
Hello!
I'm trying to create a Regular Expression to only accept "/Controller/Action" strings and I came upt with this:
"/[^a-zA-Z0-9]/[^a-zA-Z0-9]"
Now, when the code runs it throws a FormatException saying "Input string was not in a correct format." My string at this point is coming in empty. How can I only check once the property has a value or after trying to submit?
Thanks!
regularExpression
humble-apprentice
francesco ab...
All-Star
20912 Points
3279 Posts
Re: Regular Expression for Controller and Action
Mar 27, 2012 02:56 PM|LINK
I think your regular expression is wrong. You put the ^ symbol at the beginning of the [. Doyou know it negates? This meand that no char in the square bracke will be accepted. So probably you have to remove it. Moreover you have to put some repetition char, that say that the gropu may repeat several times. I think you hae to substitute each [^a-zA-Z0-9] with [a-zA-Z0-9]+
Also this way it is not...perfectly correct since controller names cannot start with a digit...first chat cannot be a digit. Moreover they can contain an underscore too...
Mvc Controls Toolkit | Data Moving Plug-in Videos
humble-appre...
Member
32 Points
73 Posts
Re: Regular Expression for Controller and Action
Mar 28, 2012 04:59 PM|LINK
I'm trying this and I'm still receiving the same exception: @"^/([A-Za-z]+)/([\w]+)$". Now when my action is called, it returns the property with @"/Controller/Action" instead of blank so that's not solving it either. The exception appears when the View is called and the model trying to show the editor for my property.
Can you tell me what is wrong with my regular expression?
humble-apprentice