Earlier, I posted about validating IP in a Text Field. Thought of sharing information about Numeric Only validation too. So, its pretty simple. Here are some lines of codes
1. @FXML
private TextField port;
2. if (!validatePort(port.getText())) {
showDialog("Invalid Port");
}
3. public boolean validatePort(final String port) {
Pattern pattern;
Matcher matcher;
String PORT_PATTERN
= "^([0-9]+)$";
pattern = Pattern.compile(PORT_PATTERN);
matcher = pattern.matcher(port);
return matcher.matches();
}
No comments:
Post a Comment