public static void validate ( String address ) throws IllegalEmailAddressException { if ( address == null ) { throw new IllegalEmailAddressException ( "<null>" , "Email address is null." ) ; } if ( address . length ( ) > 254 ) { throw new IllegalEmailAddressException ( address , "Email address is longer than 254 characters." ) ; } String [ ] parts = address . split ( "@" ) ; if ( parts . length < 2 ) { int index = address . indexOf ( ' ' ) ; if ( index == 0 ) { throw new IllegalEmailAddressException ( address , "Local part must not be empty." ) ; } else if ( index == ( address . length ( ) - 1 ) ) { throw new IllegalEmailAddressException ( address , "Domain part must not be empty." ) ; } throw new IllegalEmailAddressException ( address , "No @ character included." ) ; } if ( parts . length > 2 ) { throw new IllegalEmailAddressException ( address , "Multiple @ characters included." ) ; } try { validateDomainPart ( parts [ 1 ] ) ; validateLocalPart ( parts [ 0 ] ) ; } catch ( IllegalEmailAddressException e ) { throw new IllegalEmailAddressException ( address , e . getReason ( ) ) ; } }
Validates an email address format .