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

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -