Validating user input is the bane of every software developer's existence.Regular expression can be used effectively for doing form validation.
public static boolean validatePersonName(String objText) { // 1) must more than 2 char // 2) can not be the following char String strInValidate = "`~!@#$%^&*()_+=[]{}\\|;:\",/<>?0123456789"; try { for (int i = 0; i < objText.length(); i++) { if (strInValidate.indexOf(objText.substring(i, i + 1)) !=-1) { return false; } } return true; } catch (Exception e) { return false; } }