Data Annotations
Data Annotations
Required for anything that is not null:
[Required]
DataType for anything:
[DataType(DataType.Password)]
The data types are:
Custom = 0, // Summary: Represents a custom data type.
DateTime = 1, // Summary: Represents an instant in time, expressed as a date and time of day.
Date = 2,
Time = 3,
Duration = 4, // Summary: Represents a continuous time during which an object exists.
PhoneNumber = 5,
Currency = 6,
Text = 7,
Html = 8,
MultilineText = 9,
EmailAddress = 10,
Password = 11,
Url = 12,
ImageUrl = 13,
CreditCard = 14,
PostalCode = 15,
Upload = 16 // Summary: Represents file upload data type.
Display for anything:
[Display(Name = "Current password")]
String length checks used for Password fields:
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
Compare used for ConfirmPassword fields:
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
Regular Expressions for any restricted character set:
This one is for ExpirationDate of a credit card
[RegularExpression(@"(0[1-9]|1[0-2])\/[0-9]{2}", ErrorMessage = "Expiration should match a valid MM/YY value")]
[Phone]
Comments
Post a Comment