Hi Folks,
I've created a class which allows me to validate strings being entered into a JTextField, I've extended javax.swing.text.PlainDocument. And now I can create a JTextField like so
This basically restricts what characters and how many of them can be entered into the text field. I.e. the validatorString only contains digits, if the user tries to enter any other character it won't let them.
Now I'd like to try and extend this functionality to allow users to enter a time. So my _validatorString currently reads "0123456789:". Of course this doesn't stop the user from entering a stupid time like 25:00,:2500,25:79 etc. etc.
Any ideas how I can restrict the user to only entering in the format
00-23 : 00-59
Thanks in advance,
Paul
I've created a class which allows me to validate strings being entered into a JTextField, I've extended javax.swing.text.PlainDocument. And now I can create a JTextField like so
Code:
JTextField tf = new JTextField(new ValidatorDocument(_validatorString, _fieldLength),"",15);
This basically restricts what characters and how many of them can be entered into the text field. I.e. the validatorString only contains digits, if the user tries to enter any other character it won't let them.
Now I'd like to try and extend this functionality to allow users to enter a time. So my _validatorString currently reads "0123456789:". Of course this doesn't stop the user from entering a stupid time like 25:00,:2500,25:79 etc. etc.
Any ideas how I can restrict the user to only entering in the format
00-23 : 00-59
Thanks in advance,
Paul