我想知道是否有可能使JavaFX中的文本区域只接受文本格式,没有数字 - 在最坏的情况下,至少要在用户输入此文本区域内的数字时说明它是禁止的。
答案 0 :(得分:-1)
<强>解决方案:强> 非常简单,只需使用以下方法检查文本区域内的文本:
if (!Pattern.matches("[a-zA-Z]+", userInputText.getText())){
System.out.println("wrong input");
}
我个人在onHandleKeyReleased行动事件中添加了这个:
@FXML
public void handleKeyReleased() {
String text = userInputText.getText();
boolean disableButtons = text.isEmpty() || text.trim().isEmpty() || (!Pattern.matches("[a-zA-Z]+", userInputText.getText())) ;
okButton.setDisable(disableButtons);
}
因此,在用户在文本字段中写入任何数字后,用于确认其操作的按钮将被禁用,因此它将如下所示:
这应该适用于JavaFx中的输入UI元素。
答案 1 :(得分:-2)
代号:What is the recommended way to make a numeric TextField in JavaFX?
尝试颠倒它(接近匹配!)
<?php
$testURL = $_GET['url'];
echo $testURL;
?>