How can I check if the user entered any special characters (*, /, +, & amp ;, etc.) other than if(srt.contains("@") || srt.contains("!") || ...
?
Is there any more practical way?
And if he typed, what do I do to "lock" this typing?
How can I check if the user entered any special characters (*, /, +, & amp ;, etc.) other than if(srt.contains("@") || srt.contains("!") || ...
?
Is there any more practical way?
And if he typed, what do I do to "lock" this typing?
Try this:
if ("teste".indexOf("$") >= 0)
// Tem $
else
// Não tem $
You can put filter too, like this:
InputFilter filter = new InputFilter()
{
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
if (source.toString().contains("@"))
return "";
else
return null; // Accept original replacement.
}
};
editText.setFilters(new InputFilter[] { filter });
Similar to William's response, however, filtering only to letters or numbers.
InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if (!Character.isLetterOrDigit(source.charAt(i))) {
return "";
}
}
return null;
}
};
seuEditTxt.setFilters(new InputFilter[] { filter });