-2

I have a text box for email id for which on page loads the data will be loaded from DB

While loading, the email id which saved in wrong format was loaded. While clicking on submit button on page, the text box should be validated but doesnt validate.

Yet it validates when the textbox is focused.

Developer
  • 194
  • 2
  • 9

1 Answers1

0

There are multiple ways to validate it, one is to do it from the Model itself.

 [DataType(DataType.EmailAddress)]
 [RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessageResourceName = "InvalidEmail", ErrorMessageResourceType = "Error Message")]
    [Required]
    public string yourEmailField { get; set; }