android - How to identify character before putting it on EditText? -


while entering text on edit text want should start '#' , later contain [0-9] , [a-z]. if user tries enter first character other '#' should not display on edittext. after '#' if user enters character other [0-9] , [a-z] should not display on edittext.

for use case, preferable use inputfilter instead of textwatcher

inputfilter filter = new inputfilter() {     public charsequence filter(charsequence source, int start, int end,             spanned dest, int dstart, int dend) {          (int = start; < end; i++) {             // need handle condition 1st character should #.             if(i == 0)             {                 if(!source.charat(i).equals("#"))                     return "";             }             else if (!character.isletterordigit(source.charat(i))) {                 return "";             }         }         return null;     } }; myedittext.setfilters(new inputfilter[] { filter }); 

refer: allow letter , digit in edittext

hope helps.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -