Results 1 to 8 of 8
- 06-28-2012, 12:32 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
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.
- 06-28-2012, 01:46 PM #2
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.
- 06-28-2012, 03:44 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
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; }
- 06-28-2012, 03:52 PM #4
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.
- 06-28-2012, 04:07 PM #5
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
- 06-28-2012, 04:15 PM #6
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.
- 06-28-2012, 05:06 PM #7
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Re: How to check the value entered in the texbox is numeric or non numeric in java
This is it:
isDigit(char ch)
Thanks
- 11-18-2012, 04:22 AM #8
Senior Member
- Join Date
- Oct 2012
- Posts
- 108
- Rep Power
- 0
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!)
Or something similar to keep strings from blowing up your program.Java Code:String str; // ..... str = percent.nextLine(); try{ double d = Double.parseDouble(str); } catch(NumberFormatException nfe){ System.out.println("That's not a double!"); }
Similar Threads
-
Numeric priorities - which seems more intuitive to you?
By kjkrum in forum Forum LobbyReplies: 0Last Post: 03-19-2012, 05:09 PM -
How to test whether the entered value is numeric or it contains some characters.
By radhi16 in forum New To JavaReplies: 3Last Post: 01-19-2011, 06:25 PM -
How to test whether the entered value is numeric or it contains some characters.
By renu in forum New To JavaReplies: 13Last Post: 09-23-2010, 07:21 PM -
get numeric value from a text field
By Lehane_9 in forum New To JavaReplies: 2Last Post: 06-14-2008, 03:19 AM -
How do check I allow user to enter only alpha numeric and -?
By tanalyw in forum New To JavaReplies: 2Last Post: 04-16-2008, 12:18 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks