I have a text field (for name )that i want to prevent user to enter number, Or empty!
I try all of this, But there is some infirmity in it:
public boolean nameControl(String str) {
if (haveDigit(str)) return false; // works corrctly
else if (str.isEmpty()) return false; // Not work
else if (str.length() == 0) return false; // not work
return true;
}
As described in How to Use the Focus Subsystem: Validating Input , you may be looking for InputVerifier
. There's a related example here , among others .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.