public static void validateId ( final String id ) { if ( id == null || id . isEmpty ( ) ) { throw new IllegalArgumentException ( "The ID cannot be null or empty" ) ; } for ( int i = 0 ; i < id . length ( ) ; i ++ ) { final char c = id . charAt ( i ) ; if ( ! ( Character . isLetterOrDigit ( c ) ) ) { throw new IllegalArgumentException ( "Invalid id (\"" + id + "\"): illegal character: " + c ) ; } } if ( id . length ( ) == 1 ) { if ( Character . isDigit ( id . charAt ( 0 ) ) ) { throw new IllegalArgumentException ( "The ID cannot be an integer" ) ; } } }
Makes sure the ID has only letters and characters