Phone Number Validation MVC

Model [Required(ErrorMessage = “You must provide a phone number”)] [Display(Name = “Home Phone”)] [DataType(DataType.PhoneNumber)] [RegularExpression(@”^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$”, ErrorMessage = “Not a valid phone number”)] public string PhoneNumber { get; set; } View: @Html.LabelFor(model => model.PhoneNumber) @Html.EditorFor(model => model.PhoneNumber) @Html.ValidationMessageFor(model => model.PhoneNumber)

Custom validation attribute that compares the value of my property with another property’s value in my model class

Here’s how you could obtain the other property value: public class CustomAttribute : ValidationAttribute { private readonly string _other; public CustomAttribute(string other) { _other = other; } protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var property = validationContext.ObjectType.GetProperty(_other); if (property == null) { return new ValidationResult( string.Format(“Unknown property: {0}”, _other) ); } var otherValue … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)