Results 1 to 8 of 8
- 11-14-2010, 05:40 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 15
- Rep Power
- 0
Example to check format using regular expression?
Can anyone give me an example of how to check to see if something has a valid format, for example to check if an input has a dollar sign, two digits, a decimal, then two digits? $54.23 would be valid but say 2980 would not be valid.
Specifically, I'm trying to use regular expressions to check if a social security number has the valid format of ###-##-#### # being any digit. Any similar example that is doing this type of check would probably help me understand and allow me to figure it out.
I was just going to put it into a char array and check if the numbers were 0-9 and the -s were -s but they teacher wants us to use a regular expression to do it.
If I understand correctly, I'm going to want a Pattern, Matching, and Boolean but I'm a little confused on how to tell it to match for a pattern of 3 digits - 2 digits - 4 digits.
My java book has a short section on this which shows an example of using .matches to check if a specific word is in a string but that's not really the same as what I am trying to do here. When I try to search online for examples using matches I cant seem to find anything that is checking for a format quite like I'm looking to do. Any help?
Thanks in advance =D
- 11-14-2010, 05:45 AM #2
How advanced have you used regex before now? I don't just want to throw some expression at you and give you a ??? above your head. Have you used regex before, or the Java regex classes?
- 11-14-2010, 07:06 AM #3
Regex tutorial links provided on
Cannot make a static reference to the non-static method
db
- 11-14-2010, 07:07 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Thanks for starting the new thread.
From the old one, Darryl's links (because they're good):
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)
Edit: slow ;( because I had to alt-tab back and forwards.
- 11-14-2010, 05:42 PM #5
Member
- Join Date
- Jun 2010
- Posts
- 15
- Rep Power
- 0
Thanks for the help again, I got it figured out, pretty simple now that its done and I have a better understanding.
I notice when you make a new topic there is an option to add the prefix SOLVED. Is there a way I can mark my threads as solved after they are made?
Onto my next assignment... Lots of new concepts in this one but I think I can probably get this one on my own. We'll find out!
-
Congrats on solving it, and thanks for letting us know!
Click on the Thread Tools link above and then click on Mark this thread as solved.I notice when you make a new topic there is an option to add the prefix SOLVED. Is there a way I can mark my threads as solved after they are made?
Much luck!!Onto my next assignment... Lots of new concepts in this one but I think I can probably get this one on my own. We'll find out!
- 11-14-2010, 06:01 PM #7
Nope. That wouldn't make sense, would it?I notice when you make a new topic there is an option to add the prefix SOLVED.
Click "Thread Tools" and follow your nose.Is there a way I can mark my threads as solved after they are made?
db
- 11-14-2010, 06:05 PM #8
Member
- Join Date
- Jun 2010
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
Help with regular expression
By mr.ab18 in forum New To JavaReplies: 2Last Post: 08-06-2010, 10:01 PM -
regular expression
By prof.deedee in forum JDBCReplies: 3Last Post: 02-19-2010, 11:15 AM -
regular expression
By QkrspCmptPop in forum Advanced JavaReplies: 8Last Post: 01-20-2010, 03:55 AM -
regular expression
By ras_pari in forum Advanced JavaReplies: 27Last Post: 10-07-2009, 12:25 PM -
Complex Regular Expression HELP
By hiklior in forum New To JavaReplies: 1Last Post: 04-30-2008, 01:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks