Results 1 to 8 of 8
  1. #1
    Xycose is offline Member
    Join Date
    Jun 2010
    Posts
    15
    Rep Power
    0

    Default 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

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    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?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Regex tutorial links provided on
    Cannot make a static reference to the non-static method

    db

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    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.

  5. #5
    Xycose is offline Member
    Join Date
    Jun 2010
    Posts
    15
    Rep Power
    0

    Default

    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!

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Xycose View Post
    Thanks for the help again, I got it figured out, pretty simple now that its done and I have a better understanding.
    Congrats on solving it, and thanks for letting us know!


    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?
    Click on the Thread Tools link above and then click on Mark this thread as solved.


    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!
    Much luck!!

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    I notice when you make a new topic there is an option to add the prefix SOLVED.
    Nope. That wouldn't make sense, would it?

    Is there a way I can mark my threads as solved after they are made?
    Click "Thread Tools" and follow your nose.

    db

  8. #8
    Xycose is offline Member
    Join Date
    Jun 2010
    Posts
    15
    Rep Power
    0

    Default

    I agree it doesn't make a lot of sense, but it is actually an option. See attachment.
    Attached Thumbnails Attached Thumbnails Example to check format using regular expression?-javaforums.jpg  

Similar Threads

  1. Help with regular expression
    By mr.ab18 in forum New To Java
    Replies: 2
    Last Post: 08-06-2010, 11:01 PM
  2. regular expression
    By prof.deedee in forum JDBC
    Replies: 3
    Last Post: 02-19-2010, 12:15 PM
  3. regular expression
    By QkrspCmptPop in forum Advanced Java
    Replies: 8
    Last Post: 01-20-2010, 04:55 AM
  4. regular expression
    By ras_pari in forum Advanced Java
    Replies: 27
    Last Post: 10-07-2009, 01:25 PM
  5. Complex Regular Expression HELP
    By hiklior in forum New To Java
    Replies: 1
    Last Post: 04-30-2008, 02:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •