Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    31
    Rep Power
    0

    Default checking for ints in a String

    I have a String of a telephone number in the format xxx xxx xxxx or xxx xxxx. Is there a way to use String's methods to make sure these are ints and white space only?

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Java Code:
    for (int i = 0; i < str.length (); i ++) {
      char ch = str.charAt (i);
      if (ch != ' ' && (ch < '0' || ch > '9')) {
        //bad character
      }
    }

Similar Threads

  1. Help with checking for a certain format in a String
    By SteroidalPsycho in forum New To Java
    Replies: 2
    Last Post: 03-26-2010, 04:56 AM
  2. spliting a string and checking each token's format
    By Implode in forum New To Java
    Replies: 1
    Last Post: 10-18-2009, 08:41 PM
  3. Replies: 3
    Last Post: 08-20-2009, 03:57 PM
  4. reading in unsigned ints into a 2D array
    By newToIt in forum New To Java
    Replies: 9
    Last Post: 03-06-2009, 12:36 PM
  5. Replies: 15
    Last Post: 09-29-2008, 07:18 AM

Posting Permissions

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