Email
String email= textField.getText();
//method implementation
private boolean validMail(String email) {
Pattern emailPattern = Pattern.compile(".+@.+\\.[a-z]+");
Matcher emailMatcher = emailPattern.matcher(email);
return emailMatcher.matches();
}
//method calling
if(validMail(email))
JOptionPane.showMessageDialog(rootPane, "email is right");
else
JOptionPane.showMessageDialog(rootPane, "wrong email");
Password
String pw =textField_1.getText();
//method implementation
private boolean validPassword(String pw){
Pattern passwPattern = Pattern.compile("[A-Za-z0-9]{0,6}");
Matcher passwMatcher = passwPattern.matcher(pw);
return passwMatcher.matches();
}
No comments:
Post a Comment