Results 1 to 8 of 8
  1. #1
    newbie_tiwari is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Question How to check the value entered in the texbox is numeric or non numeric in java

    Hi all,

    I am newbie in RFT aswell as in java so could u pls help me
    actually i want to check for a textbox that the value we entered is numeric or non numeric as the textbox will only take the numeric value.. pls guyss help me.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: How to check the value entered in the texbox is numeric or non numeric in java

    One way would be to use the Integer class's parseInt() method in a try/catch block
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Java2012 is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Re: How to check the value entered in the texbox is numeric or non numeric in java

    Another way...... please take a look at this code:


    Java Code:
    public  boolean isnum(String st)
      {
          boolean yes = true;
          
          for(int i = 0; i < st.length();i++)
          {
              if(!helpIsnum(st.charAt(i)))
              {
                 yes = false;
                 break;
              }
          }
          
          return yes;
      }
      
      public  boolean helpIsnum(char c)
      {
          boolean yes = false;
          
          if("0123456789.".contains("" + c))
              yes = true;
          
          
          return yes;
          
      }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: How to check the value entered in the texbox is numeric or non numeric in java

    The Character class has a method that says if a char is numeric.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Java2012 is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Re: How to check the value entered in the texbox is numeric or non numeric in java

    Quote Originally Posted by Norm View Post
    The Character class has a method that says if a char is numeric.
    In this case, he does not need the help function.

    Can you name that char class function please?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: How to check the value entered in the texbox is numeric or non numeric in java

    Take a look at the API doc. It is all documented there. The Character class has lots of useful methods.
    Java Platform SE 6
    http://docs.oracle.com/javase/7/docs/api/index.html

    Find the class in the lower left and click on the link for the doc to be shown in the main frame.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Java2012 is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Re: How to check the value entered in the texbox is numeric or non numeric in java

    This is it:

    isDigit(char ch)

    Thanks

  8. #8
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default Re: How to check the value entered in the texbox is numeric or non numeric in java

    Well.. yearly is not a char. Character.isDigit(char c) is for one char....

    This program will crash before then anyway when the percent.nextInt() fires on a string.... (nextInt() gets an int value out of stdin, not a double!)

    Java Code:
         String str;
         // .....
         str = percent.nextLine();
         try{
    		double d = Double.parseDouble(str);
    	}
         catch(NumberFormatException nfe){
    		System.out.println("That's not a double!");
         }
    Or something similar to keep strings from blowing up your program.

Similar Threads

  1. Replies: 0
    Last Post: 03-19-2012, 06:09 PM
  2. Replies: 3
    Last Post: 01-19-2011, 07:25 PM
  3. Replies: 13
    Last Post: 09-23-2010, 08:21 PM
  4. get numeric value from a text field
    By Lehane_9 in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 04:19 AM
  5. Replies: 2
    Last Post: 04-16-2008, 01:18 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
  •