EditText Android Filter for IP Address ###.###.###.###? -


i use filter validate ip address

localip.sethinttextcolor(color.parsecolor("#aaaaaa"));         inputfilter[] filters = new inputfilter[1];         filters[0] = new inputfilter() {             public charsequence filter(charsequence source, int start, int end, spanned dest, int dstart, int dend) {                 if (end > start) {                     string desttxt = dest.tostring();                     string resultingtxt = desttxt.substring(0, dstart) + source.subsequence(start, end) + desttxt.substring(dend);                     if (!resultingtxt.matches ("^\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3})?)?)?)?)?)?")) {                         return "";                     } else {                         string[] splits = resultingtxt.split("\\.");                         (int i=0; i<splits.length; i++) {                             if (integer.valueof(splits[i]) > 255) {                                 return "";                             }                         }                     }                 }                 return null;             }         };         localip.setfilters(filters); 

the result allowed ##.##.##.##, want have max of ###.###.###.###. how do ?

inputfilter[] filters = new inputfilter[1];         filters[0] = new inputfilter() {             @override             public charsequence filter(charsequence source, int start, int end,                     android.text.spanned dest, int dstart, int dend) {                 if (end > start) {                     string desttxt = dest.tostring();                     string resultingtxt = desttxt.substring(0, dstart)                             + source.subsequence(start, end)                             + desttxt.substring(dend);                     if (!resultingtxt                             .matches("^\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3})?)?)?)?)?)?")) {                         return "";                     } else {                         string[] splits = resultingtxt.split("\\.");                         (int = 0; < splits.length; i++) {                             if (integer.valueof(splits[i]) > 255) {                                 return "";                             }                         }                     }                 }                 return null;             }          };         edittxxt.setfilters(filters); 

or give at

http://kmansoft.com/2011/02/27/an-edittext-for-entering-ip-addresses/


Comments