c# - Restricting number of continuous comma in a textbox -
how limit number of continuous 'comma' in textbox?...ex should not allow user enter more 2 comma continuously
this should handle scenarios, believe:
private void textbox_textchanged(object sender, eventargs e) { textbox tb = sender textbox; if (tb != null) { int pos = tb.selectionstart; int length = tb.text.length; tb.text = tb.text.replace(",,", ","); int diff = length- tb.text.length; tb.selectionstart = pos == 0 || diff == 0 ? pos : pos - diff; } } this works when type text textbox, when paste text it.
Comments
Post a Comment