To validate an email address:
^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$To validate a password for basic complexity:
^\\w*(?=\\w*\\d)(?=\\w*[a-z])(?=\\w*[A-Z])\\w*$
The password complexity regex verifies that the password String contains at least 1 number, at least 1 lower case letter, and at least one upper case letter. In addition to Java, I've used these regular expressions in JavaScript and PHP. They work well for most needs. Continue reading for code samples.
if ( !email.matches("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+" +
"(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$") ) {
throw new Exception( "Error, bad email address." );
}... and ...
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." );
}

Did you find this post helpful, or at least, interesting?