我想验证联系人的文本字段以检查它是否包含数字。 我已经为 KeyTyped 编写了以下函数,但它不起作用,任何人都可以提供替代方案。提前致谢。
代码:-
private void tnoKeyTyped(java.awt.event.KeyEvent evt)
{
char c=evt.getKeyChar();
System.out.println("hi");
if(!(Character.isDigit(c)||(c==KeyEvent.VK_BACK_SPACE)||(c==KeyEvent.VK_DELETE)))
{
evt.consume();
}
}
最佳答案
I want to validate the contact no Text Field for checking if it contains digit
您可以使用 InputVerifer
对字段进行后验证,请参阅 Validating Input了解更多详情。
I have written following function for KeyTyped but it is not working can anybody provide an alternative
您可以通过使用 DocumentListener
进行实时验证,请参阅 Implementing a Document Filter和 DocumentFilter Examples了解更多详情
关于java - 联系电话验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30931001/