Search code examples
javaswingjtextfield

Validate JTextField


How do I validate JTextField for a personal number? For example, I would like it to validate something formatted like 841017-4567.


Solution

  • Read up on JFormattedTextField and MaskFormatter.

    JFormattedTextField phoneField = new JFormattedTextField(new MaskFormatter("######-####"));