ValidationUtils { public static boolean coordinateIsValid( String coordinate ) { if ( coordinate == null || coordinate.trim().isEmpty() ) { return false; } Matcher matcher = POINT_PATTERN.matcher( coordinate ); if ( !matcher.find() ) { return false; } double longitude = 0.0; double latitude = 0.0; try { longitude = Double.parseDouble( matcher.group( 1 ) ); latitude = Double.parseDouble( matcher.group( 2 ) ); } catch ( NumberFormatException ex ) { return false; } return longitude >= LONG_MIN && longitude <= LONG_MAX && latitude >= LAT_MIN && latitude <= LAT_MAX; }  static boolean expressionIsValidSQl( String filter ); static boolean emailIsValid( String email ); static boolean dateIsValid( String date, Locale locale ); static boolean dateIsValid( String date ); static boolean timeIsValid( String time ); static boolean urlIsValid( String url ); static boolean uuidIsValid( String uuid ); static boolean usernameIsValid( String username ); static boolean passwordIsValid( String password ); static boolean coordinateIsValid( String coordinate ); static boolean bboxIsValid( String bbox ); static String getLongitude( String coordinate ); static String getLatitude( String coordinate ); static Point2D getCoordinatePoint2D( String coordinate ); static String getCoordinate( String longitude, String latitude ); static String dataValueIsValid( String value, DataElement dataElement ); static String dataValueIsValid( String value, ValueType valueType ); static boolean dataValueIsZeroAndInsignificant( String value, DataElement dataElement ); static String commentIsValid( String comment ); static String storedByIsValid( String storedBy ); static boolean isValidHexColor( String value ); static Object getSubstitutionValue( ValueType valueType ); static String normalizeBoolean( String bool, ValueType valueType ); static boolean validateRenderingType( Class<?> clazz, ValueType valueType, boolean optionSet, ValueTypeRenderingType type ); static boolean validateWhatsapp( String whatsapp ); static boolean validateInternationalPhoneNumber( String phoneNumber ); static final ImmutableSet<String> ILLEGAL_SQL_KEYWORDS; }
@Test public void testCoordinateIsValid() { assertTrue( coordinateIsValid( "[+37.99034,-28.94221]" ) ); assertTrue( coordinateIsValid( "[37.99034,-28.94221]" ) ); assertTrue( coordinateIsValid( "[+37.99034,28.94221]" ) ); assertTrue( coordinateIsValid( "[170.99034,78.94221]" ) ); assertTrue( coordinateIsValid( "[-167,-28.94221]" ) ); assertTrue( coordinateIsValid( "[37.99034,28]" ) ); assertFalse( coordinateIsValid( "23.34343,56.3232" ) ); assertFalse( coordinateIsValid( "23.34343 56.3232" ) ); assertFalse( coordinateIsValid( "[23.34f43,56.3232]" ) ); assertFalse( coordinateIsValid( "23.34343,56.323.2" ) ); assertFalse( coordinateIsValid( "[23.34343,56..3232]" ) ); assertFalse( coordinateIsValid( "[++37,-28.94221]" ) ); assertFalse( coordinateIsValid( "S-0.27726 E37.08472" ) ); assertFalse( coordinateIsValid( null ) ); assertFalse( coordinateIsValid( "-185.12345,45.45423" ) ); assertFalse( coordinateIsValid( "192.56789,-45.34332" ) ); assertFalse( coordinateIsValid( "140.34,92.23323" ) ); assertFalse( coordinateIsValid( "123.34,-94.23323" ) ); assertFalse( coordinateIsValid( "000.34,-94.23323" ) ); assertFalse( coordinateIsValid( "123.34,-00.23323" ) ); }