asp.net mvc 3 - How to validate textbox in MVC3 that must contain string started with characters "PR" -
i new mvc3 , working mvc3 razor application. need validate textbox on view in such way that, textbox accept strings starting characters "pr" , 4th character of string must "2". great if helps me. in advance
well need regex. i'm not sure regex , string contains. if need have 2 matches in there, split , use 2 textboxes , join values on post.
viewmodel:
public class myviewmodel { [regularexpression("^pr[a-za-z0-9]", errormessage= "invalid text1")] public string mytext1 { get; set; } [regularexpression("^2[a-za-z0-9]", errormessage= "invalid text2")] public string mytext2 { get; set; } }
warning, regex may faulty. invite others edit/post comments , can update correct regex
view:
@model myproject.models.myviewmodel @using (html.beginform()) { @html.textboxfor(m => m.mytext1) @html.textboxfor(m => m.mytext2) <button type="submit">submit</button> }
hope helps
Comments
Post a Comment