我的 swing 组件中有两个文本字段。在一个文本字段中,我只需要有数字 (没有字符串、空格、允许的特殊字符)并且在另一个文本字段中我只需要有字符串(没有数字、空格、允许的特殊字符)。我该如何实现……???
最佳答案
您可以使用 Pattern用于验证输入的类(正则表达式)。提供简短教程 here .
我很确定基础教程涵盖了所有这些......
"^//d+$" //The text must have at least one digit, no other characters are allowed
"^[a-zA-Z]+$" //The text must have at least one letter, no other characters are allowed
关于java - Java Swing 中 JTextfield 中的控制空格、数字、特殊字符、字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4645234/