Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Help With Validation

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help With Validation

    So I'm trying to use two validations in my program:
    5 integers for the first Validation and
    the second is 32 characters only including : and |.

    The first validation is for a Zip Code and the second is for a Bar Code.

    I'm just clueless on how to perform these validations.

    My program is set us so you go and it asks enter Z to enter a Zip Code or B to enter a Bar code. From here I have 2 if statements ( if (choice.equals("Z") then perform the Zip Code Part of the Program and if (choice.equals("B") to go to the Bar Code part of the program.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help With Validation

    See How to use regular expressions. For example, you could use "[0-9]{5}" to validate the zip code (using String.matches)

  3. #3
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: Help With Validation

    Quote Originally Posted by copeg View Post
    For example, you could use "[0-9]{5}" to validate the zip code (using String.matches)
    I suppose you mean "^[0-9]{5}$"

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help With Validation

    Quote Originally Posted by JavaHater View Post
    I suppose you mean "^[0-9]{5}$"
    No I do not. The ^ is not necessary for something like String.matches in the above context (although it doesn't muck anything up either )

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help With Validation

    http://www.javaprogrammingforums.com...explained.html

    http://www.javaprogrammingforums.com...pressions.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. int / double validation
    By exnuke1972 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 20th, 2011, 05:08 PM
  2. Exception during xml validation
    By vijeta in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 6th, 2010, 02:50 AM
  3. IPv6 validation
    By subhvi in forum Java Networking
    Replies: 1
    Last Post: November 27th, 2009, 07:19 AM
  4. Input Validation
    By nic in forum AWT / Java Swing
    Replies: 4
    Last Post: November 18th, 2009, 10:54 AM
  5. Problems with If validation
    By websey in forum Loops & Control Statements
    Replies: 1
    Last Post: November 18th, 2009, 09:43 AM