Results 1 to 4 of 4
  1. #1
    Krik is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default Regular expression

    Hi, all.
    I have the brightest question of the month: how would I check my code for the list of string regular expressions? (I want to prevent the possibility of user asking question with unassigned symbols(

    Here is the list, for example - the purpose is to ask the user "what do you want on your sandwich"
    Then he is given the list, let's say, "ketchup", mayonnaise."
    How would I prevent him from entering, let's say, "shoes", or just a bunch of numbers ....

    I figured out it should be regular expressions, I still don't know how to incorporate it into my code. When I tried to solve the problem with boolean logics, the program crushed for example, if customer should make one choice out of "no" and two ingredients ... I couldn't find a way to fix it.

    so any ideas would be great.
    Thanks.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: Regular expression

    I'm not sure how regular expressions would help you here.

    If you have a finite amount of valid responses, add them all to a List. When the user enters a choice, make sure what they chose is in the List. If it's not, it's not a valid choice.

    Or you could use a drop-down box JComboBox instead of having them enter free text, but that's only valid if you're using a GUI.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Regular expression

    Moved from Forum Guides

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Regular expression

    Quote Originally Posted by KevinWorkman View Post
    Or you could use a drop-down box JComboBox instead of having them enter free text, but that's only valid if you're using a GUI.
    And if this is a command line application, you could display a menu with the valid choices each on its own line with a serial number and prompt the user to enter a number rather than a word.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Regular expression
    By garnaout in forum New To Java
    Replies: 4
    Last Post: 05-15-2012, 06:22 PM
  2. regular expression
    By ehsansad in forum New To Java
    Replies: 8
    Last Post: 03-18-2011, 02:23 PM
  3. Help with regular expression
    By mr.ab18 in forum New To Java
    Replies: 2
    Last Post: 08-06-2010, 10:01 PM
  4. regular expression
    By QkrspCmptPop in forum Advanced Java
    Replies: 8
    Last Post: 01-20-2010, 03:55 AM
  5. regular expression
    By ras_pari in forum Advanced Java
    Replies: 27
    Last Post: 10-07-2009, 12:25 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
  •