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 10 of 10

Thread: Little easy to fix problem

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Little easy to fix problem

    Hi guys (Using java ME but syntax is the same)

    I am new to java and also new to the forums

    I have a quick question that im sure you guys can help me with..

    How in java to you make sure that a username (textbox) has a number in it... for example jon will show an error messege but jon43 wont....

    here is my current code. I know this code works but I would like to know how do do it.... thanks

    if (ID.equals(""))
    {
    String Invalid = " UserID invalid ";
    mAlertInvalidUser.setString(StrmAlertInvalid);
    mDisplay.setCurrent(mAlertInvalid);


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Little easy to fix problem

    Recommended reading: Pattern (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Little easy to fix problem

    Sorry I am very new and i dont understand most of what I just read... could you give some more assistance to my problem

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Little easy to fix problem

    That link talks about regular expressions. Basically, regular expressions tell you whether a particular pattern (like a number) can be found inside another String.

    Hint- The pattern you're looking for is any number of any kind of character, then a number, then any number of any kind of character, right?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Little easy to fix problem

    yes indeed. so if its jon it kicks up an error but if its jon23 it does not

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Little easy to fix problem

    Quote Originally Posted by adammint7 View Post
    yes indeed. so if its jon it kicks up an error but if its jon23 it does not
    Yep. So your next step is to throw together a regular expression that matches that pattern.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Little easy to fix problem

    This is the thing.. I am not sure how. could you give me an example??

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Little easy to fix problem

    Quote Originally Posted by adammint7 View Post
    This is the thing.. I am not sure how. could you give me an example??
    Google is your friend for example regular expressions. But here's one that tests whether the String "cat" can be found in another String:
    Pattern p = Pattern.compile(".*cat.*");
    		 Matcher m = p.matcher("test cat test");
    		 boolean b = m.matches();
     
    		 System.out.println(b);
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Little easy to fix problem

    how would I put that into an if statement for names, I have not used that methodology before

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Little easy to fix problem

    Quote Originally Posted by adammint7 View Post
    how would I put that into an if statement for names, I have not used that methodology before
    What have you tried? Which part of that are you stuck on? Iterating over names? Using an if statement? Something else? You can't just keep asking general questions, as they're actually much harder to answer than specific questions about code.

    Post an SSCCE (not your entire program) that demonstrates what you've tried and where you're stuck and ask a specific question, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Easy array question
    By surfbumb in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2011, 09:44 PM
  2. Easy help but can't figure it out.
    By weezer562 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 19th, 2010, 09:50 PM
  3. My Custom Layout (VERY EASY TO USE)
    By aussiemcgr in forum AWT / Java Swing
    Replies: 10
    Last Post: August 5th, 2010, 01:37 PM
  4. A Few Quick, Easy Questions
    By TheAsianMenace in forum Object Oriented Programming
    Replies: 1
    Last Post: February 24th, 2010, 02:47 PM
  5. JAVA Image Icon and JButton resizing problem
    By antitru5t in forum AWT / Java Swing
    Replies: 1
    Last Post: March 13th, 2009, 04:39 AM