I want to validate phone number field in swing, so I am writing code to allow user to enter only digits, comma, spaces. For this I am using regular expression, when user enter characters or other than the pattern text field will consume.
My code is not working. Can anyone tell me what the problem is?
String s = c_phone.getText();
Pattern pattern = Pattern.compile("([0-9\\-\\(\\)\\,]+)");
Matcher m = pattern.matcher(s);
if((!m.matches())){
evt.consume();
}
Thanks in advance.