-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.

3
  • on page load you can validate form, $(form).validate() Commented Oct 11, 2017 at 11:01
  • Possible duplicate of Email address validation using ASP.NET MVC data type attributes Commented Oct 11, 2017 at 11:32
  • Make sure you have js scripts for validation like in the above link, then add validation attributes to the model. Commented Oct 11, 2017 at 11:35

1 Answer 1

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; }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.