jquery - validate model on change of texbox event -
i have model class
public class actorphonemodel { public int phonetypetd { get; set; } public string phonetype { get; set; } [stringlength(30, errormessageresourcetype = typeof(errormessage), errormessageresourcename = "phone_number_you_entered_must_be_at_least_five_characters", errormessage = "", minimumlength = 5)] [regularexpression(@"/^[ 0-9()+-]*$/", errormessageresourcetype = typeof(errormessage), errormessageresourcename = "phone_number_is_invalid", errormessage = "")] public string phonenumber { get; set; } }
and on view
@foreach (var phone in model.phones) { <tr> <td>@phone .phonetype</td> <td> @html.textboxfor(m => phone .phonenumber, new { @class = "phonenumber form-control", data_phonetype = @phone .phonetypetd, data_actorid = model.actorid, maxlength = "30" }) </td> </tr> }
i using ajax post save changed phone number. , on text changed event of textbox want validate model
$(".phonenumber").change(function () { var phonetype = $(this).attr("data-phonetype"); var actorid = $(this).attr("data-actorid"); var phonenumber = $(this).val(); if (//validate model) { //code save phone number of phonetype } });
how can validate model in jquery.. have tried method form.valid() not working me.
i guess have validate jquery only, since on change of text there no server side call. , need validate 1 field can go regularexpression jquery. simpler. hope helps.
Comments
Post a Comment