The following is code block, where i have been trying to validate jFormatedTextFeild. When a key is typed (any key) code block does seem to execute for the first key typed. But works fine for second key typed ! Please help me :(
private void jFormattedTextField_ByingPriceKeyTyped(KeyEvent evt) {
System.out.println("key typed action ");
String checking = jFormattedTextField_ByingPrice.getText();
Pattern ptrn = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
Matcher match = ptrn.matcher(checking);
if(match.find()){
txtPriceMessage.setVisible(true);
//text field which contains the message does not appears
//for first key typed only it appears when second key is typed.
} else {
txtPriceMessage.setVisible(false);
}
}
Use a DocumentFilter
to filter the values going to a text component in real time, that's what it's design for. Take a look at these examples, there's even a PatternFilter
for using with regular expressions...
For post validation, use a InputVerifier