How to make JTextField or JFormattedTextField accept input only if it matches a REGEX pattern?
问题 I want a few JTextField within my program to only accept new input if it matches an specific Pattern . I know about JFormattedTextField 's masks and that is not what I want here. For each new input, the text should only accept the changes if those comply with the flow of an specific regex pattern. This has to be done with regex because of "regex-demanding" situations, like if the input should receive parts of itself. This is better understood with an example: Suppose my regex is "(\\d{2})-bk\