Created
December 16, 2016 10:30
-
-
Save anymaniax/49ea7a39d84867a1f1bc6605fbf80c7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("\\."); | |
for (int i = 0; i < splits.length; i++) { | |
if (Integer.valueOf(splits[i]) > 255) { | |
return ""; | |
} | |
} | |
} | |
} | |
return null; | |
} | |
}; | |
et_setting_ip.setFilters(filters); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment