boolean checkValidity (String str, String regex) {
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(str);
    if (m.matches()) {
        return true;
    } else {
         return false;
    }
}

09-04 05:03