
hi
could you please send me code for login validations Email validation and password email should be in correct format and valid password in java

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
import java.util.regex.*;
class Validations extends JFrame{
JLabel l1,l2;
JLabel lab1,lab2;
JTextField t1;
JPasswordField t2;
JPanel p;
Validations(){
l1=new JLabel("Enter Email:");
t1=new JTextField(20);
l2=new JLabel("Enter Password: ");
t2=new JPasswordField(20);
lab1=new JLabel();
lab2=new JLabel();
p=new JPanel(new GridLayout(2,3));
p.add(l1);
p.add(t1);
p.add(lab1);
p.add(l2);
p.add(t2);
p.add(lab2);
add(p);
setVisible(true);
pack();
lab1.setVisible(false);
lab2.setVisible(false);
t1.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String email=t1.getText();
String exp="^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
CharSequence seq = email;
Pattern pattern = Pattern.compile(exp,Pattern.CASE_INSENSITIVE);
Matcher m = pattern.matcher(seq);
if (m.matches()) {
lab1.setVisible(false);
}
else {
lab1.setText("*Invalid Email ID");
lab1.setVisible(true);
lab1.setForeground(Color.red);
}
}
});
t2.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String input = t2.getText();
if((input.length())==0){
lab2.setVisible(true);
lab2.setText("Enter Password!");
lab2.setForeground(Color.red);
}
else{
lab2.setVisible(false);
}
}
});
}
public static void main(String[]args){
Validations v=new Validations();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.