Allow only alphabetic name in text box in c# -
i need allow user enter alphabetic name in text box e.g jhon or kamran khan. got info different links nothing working yet. in code text box values started numbers e.g 3kamran need not allow 3 or other number. using c# windows app , code looks like.
private void txtname_textchanged(object sender, eventargs e) { if (system.text.regularexpressions.regex.ismatch(txtname.text, "^[a-za-z]+$")) { messagebox.show("enter valid name", "error", messageboxbuttons.ok, messageboxicon.error); txtname.text.remove(txtname.text.length - 1); txtname.clear(); txtname.focus(); } }
private void txtname_textchanged(object sender, eventargs e) { //here problem add ! in font if(!string.isnullorwhitespace(txtname)) // prevent exception when textbox empty { if (!system.text.regularexpressions.regex.ismatch(txtname.text, "^[a-za-z]+$")) { messagebox.show("enter valid name", "error", messageboxbuttons.ok, messageboxicon.error); txtname.text.remove(txtname.text.length - 1); txtname.clear(); txtname.focus(); } } }
Comments
Post a Comment