Validate JTextField value so that it starts with “RA” then has 8 digits
问题 I have a JTextField where in the user has to input the data. Its value has to always start with RA and must have exactly 8 digits after it. So, its length will be 10 always. for e.g., RA12345678 . How do I do this in Java? I tried using MaskFormatter and JFormattedTextField but, did not achieve the results. I need to validate the input with length together. 回答1: I'd use a JSpinner for this, and simply prefix RA to the number. E.G. Image Typical Output RA8007006 Code import java.awt.*; import