The following Constrains checks the data type :
Constraint | Inline | Class | Description |
---|---|---|---|
int | {id:int} |
IntRouteConstraint | Constrains a route parameter to represent only 32-bit integer values |
alpha | {id:alpha} |
AlphaRouteConstraint | Constrains a route parameter to contain only lowercase or uppercase letters A through Z in the English alphabet. |
bool | {id:bool} |
BoolRouteConstraint | Constrains a route parameter to represent only Boolean values. |
datetime | {id:datetime} |
DateTimeRouteConstraint | Constrains a route parameter to represent only DateTime values. |
decimal | {id:decimal} |
DecimalRouteConstraint | Constrains a route parameter to represent only decimal values. |
double | {id:double} |
DoubleRouteConstraint | Constrains a route parameter to represent only 64-bit floating-point values. |
float | {id:float} |
FloatRouteConstraint | Matches a valid float value (in the invariant culture - see warning) |
guid | {id:guid} |
GuidRouteConstraint | Matches a valid Guid value |
The following Constrains checks the Value/Range/Length etc :
Constraint | Inline | Class | Description |
---|---|---|---|
length(length) | {id:length(12)} |
LengthRouteConstraint | Constrains a route parameter to be a string of a given length or within a given range of lengths. |
maxlength(value) | {id:maxlength(8)} |
MaxLengthRouteConstraint | Constrains a route parameter to be a string with a maximum length. |
minlength(value) | {id:minlength(4)} |
MinLengthRouteConstraint | Constrains a route parameter to be a string with a maximum length. |
range(min,max) | {id:range(18,120)} |
RangeRouteConstraint | Constraints a route parameter to be an integer within a given range of values. |
min(value) | {id:min(18)} |
MinRouteConstraint | Constrains a route parameter to be a long with a minimum value. |
max(value) | {id:max(120)} |
MaxRouteConstraint | Constrains a route parameter to be an integer with a maximum value. |
Using Regular expression or regex as constraint offers more flexibility to limit any input :
Constraint | Inline | Class | Description |
---|---|---|---|
regex(expression) | {ssn:regex(^\\d{{3}}-\\d{{2}}-\\d{{4}}$)} |
RegexRouteConstraint | Constrains a route parameter to match a regular expression. |