I have a username textbox on a form, that has a few validation rules applied to it via the DataAnnotation attributes:
[Required(ErrorMessage = "FTP login is required")]
[StringLength(15, ErrorMessage = "Must be 15 characters or fewer")]
[RegularExpression(@"[a-zA-Z0-9]*", ErrorMessage = "Alpha-numeric characters only")]
public string FtpLogin { get; set; }
I also have a button next to this text box, that fires off a jQuery ajax request that checks for the existence of the username as follows:
<button onclick="check(this);return false;" id="FtpLoginCheck" name="FtpLoginCheck">Available?</button>
I'm looking for a way of tieing the two together, so that the client-side validation is performed before the call to the "check(this)" in the onclick event.
Edit: To be more clear, I need a way to inspect or trigger the client-side validation result of the textbox, when I click the unrelated button beside it.
Edit: I now have the button JS checking for $("form").validate().invalid, but not displaying the usual validation messages. Almost there
Any ideas?