private static void validateRegex(String fieldName,String value,String pattern) throws Exception {
  if (!matches(pattern,value)) {
    throw new Exception();
  }
}

private static void validateRegex ( String fieldName , String value , String pattern ) throws Exception { if ( ! matches ( pattern , value ) ) { throw new Exception ( ) ; } }
validates a field using a regular expression .
