Results 1 to 5 of 5
Thread: matching problem
- 02-12-2011, 06:11 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
matching problem
can someone please tell me what I am missing in this field cheker. I only want it to take numbers but it still takes letters
Java Code:gpaField.setColumns(4); String gpcheck = gpaField.getText(); //float gpanum = Float.parseFloat(gpaField.getText()); if (gpcheck.length()<= 0 || gpcheck.length()>=4 || gpcheck.matches("^([0-9]{0,1}[.]{1}[0-9]{3})")){ JOptionPane.showMessageDialog(null, "Please enter correct GPA"); gpaField.setBackground(Color.yellow); IllegalArgumentException exception = new IllegalArgumentException("Invalid input"); throw exception; } else { gpaField.setBackground(new JTextField().getBackground()); }
- 02-12-2011, 08:08 PM #2
Your IF statement says:
"If the length is less than zero, or the length is greater than four, or it is a number with 3 decimal places, then it is invalid."
What you want it to say:
"If the length is less than zero, or the length is greater than four, or it is NOT a number with 3 decimal places, then it is invalid."
- 02-12-2011, 08:51 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
so how do I say NOT I tried ! no luck and the Pattern (Java 2 Platform SE v1.4.2)
doesn't really specify a NOT
-
For NOT, use !. You've used ! in if statements before surely. And if it doesn't work, then we can't help you unless you post your attempt.
- 02-12-2011, 09:20 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Need help with matching game
By soundymcsoundsound in forum New To JavaReplies: 2Last Post: 11-02-2010, 11:09 PM -
Reflective constructor matching problem
By baizba in forum Advanced JavaReplies: 2Last Post: 09-28-2010, 09:31 PM -
Paranthesis Matching???
By MuslimCoder in forum New To JavaReplies: 1Last Post: 10-27-2009, 06:02 AM -
Help with signature matching
By cachi in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks