-1

I'm trying to validate a text field using IF statements.

When I use:

if(fname.getText().matches("[a-z]") || fname.getText().matches("[A-Z]")) {
                    grid1.getChildren().remove(labelstar1);                 
                }

It only matches one character. How do I make it validate so it matches with a string of characters with no specific length?

Any help/thoughts would be appreciated!

dan6657
  • 117
  • 2
  • 11

1 Answers1

1

This should help you!

if(fname.getText().matches("[a-zA-Z]+")) {
                    grid1.getChildren().remove(labelstar1);                 
}

Similar thing has already been answered here Check if String contains only letters

Community
  • 1
  • 1
JavaHopper
  • 5,567
  • 1
  • 19
  • 27