I want to know what's wrong with this code? I am taking my input in the textbox(A 10-digit mobile number). My problem is that, this code all the time prints else statement even if my input is correct.
mobNo=textMobNo.getText();
textMobNo.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
Pattern pattern = Pattern.compile("^[789]\\d{9}$");
Matcher matcher = pattern.matcher(mobNo);
if (matcher.matches()){
System.out.println("valid");
}
else{
System.out.println("invalid");
}
}
@Override
public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
};
});