Restrict the input in textfield/textbox to alphanumeric only in J2me
How can I restrict the user to input in textfield/textbox to alphanumeric开发者_如何转开发 only in J2ME ? I don't want the user to input !@##$%$#*& <-- these special characters.
override method TextField in way below and put logic their
TextField t = new TextField(){
protected boolean validChar(String c) {
if ((c.charAt(0) > '0' && c.charAt(0) < '9') || (c.charAt(0) > 'a' && c.charAt(0) < 'z') || (c.charAt(0) > 'A' && c.charAt(0) < 'Z' )) {
return true;
}else{
return false;
}
}
};
精彩评论