public class RegexTester { public static void main ( String [ ] args ) { if ( args.length < 2 ) { usage(); System.exit(2); } String email = args[ 0 ]; String password = args[ 1 ]; try { checkEmailAddress( email ); checkPassword( password ); System.out.println( "Email and password OK." ); } catch ( Exception e ) { System.err.println( e.getMessage() ); System.exit(1); } System.exit(0); } public static void checkEmailAddress ( String email ) throws Exception { if ( !email.matches("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+" + "(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$") ) { throw new Exception( "Error, invalid email address" ); } } public static void checkPassword ( String password ) throws Exception { if ( !password.matches("^\\w*(?=\\w*\\d)(?=\\w*[a-z])(?=\\w*[A-Z])\\w*$") || password.length() < 8 ) { throw new Exception( "Error, bad password or password not complex enough." ); } } public static void usage ( ) { System.err.println( "Usage: java RegexTester username password" ); } } /* RegexTester */