Custom Validation & Data Annotations

Discussion in 'ASP.NET / ASP.NET Core' started by maxsellarco, Aug 7, 2011.

  1. This is an annotated variable.

    [healeyAtrribute(ErrorMessageResourceName = "ValidationErrorInvalidEmail",
    ErrorMessageResourceType = typeof(maxsellar_1.Web.Resources.ValidationErrorResources))]
    public string Email { get; set; }

    Ehe following code provides the error checking and should fire off the
    error if there is one.

    public class healeyAtrribute : ValidationAttribute
    {
    public override bool IsValid(object value)
    {
    if (value.ToString().Equals("[email protected]"))
    {
    return false;
    }
    return true;
    }


    }

    When I enter the email string, '[email protected]', it does not work.

    Any suggestions?

    Regards,

    Mike
     
  2. Nothing goes wrong if ValidationResult.Success is returned from the validation function, 'Isvalid'. However ii I enter a praticular email string there is no immediate error on the form but there is a failure upon submitting the form.
    The message is, "invoke operation, 'CreateUser' failed validation. Please inspect ValidationErros for details.

    What is supposed to happen is, upon losing focus to this field an error message becomes attached to the box on the form but this does not happen, Somehow the error is not getting to the proper place.
     

Share This Page