test if a string is an integer?
2010-09-19 20:01
453 查看
http://bytes.com/topic/java/answers/18107-test-if-string-integer
"dave" <go_away_you_spammer_scum@nowhere.com> wrote in message
news:FAHJc.59786$Xb4.4468@nwrdny02.gnilink.net...[color=blue]
> I am reading input from a form. I want to validate the input by making[/color]
sure[color=blue]
> that the string is actually an integer. How would I do this? Do i need to
> convert it to a character array and break down each character and test it?
> or is there an easier way? Thanks.
>[/color]
Try to perform Integer.parseInt(yourString) and if it throws a
NumberFormatException you'll know the string isn't a valid integer
"dave" <go_away_you_spammer_scum@nowhere.com> wrote in message
news:FAHJc.59786$Xb4.4468@nwrdny02.gnilink.net...[color=blue]
> I am reading input from a form. I want to validate the input by making[/color]
sure[color=blue]
> that the string is actually an integer. How would I do this? Do i need to
> convert it to a character array and break down each character and test it?
> or is there an easier way? Thanks.
>[/color]
Try to perform Integer.parseInt(yourString) and if it throws a
NumberFormatException you'll know the string isn't a valid integer
public Boolean isInt10(String int10) { try { Integer.parseInt(int10); } catch(NumberFormatException ex) { return false; } return true; }
相关文章推荐
- test if a string is an integer?
- Given an integer, write a function to determine if it is a power of two
- EasyTest would get stuck if the json string is corrupted
- How do you test if an NSString is empty
- Ten Ways to Check if an Integer Is a Power Of Two in C
- test if a string is a number
- 给.Net程序员的PInvoke Tips [1]: String is Sometimes an Integer
- mybatis String的if条件判断问题 There is no getter for property named 'xxx' in 'class Java.lang.Integer'
- Ten Ways to Check if an Integer Is a Power Of Two in C
- Ten Ways to Check if an Integer Is a Power Of Two in C
- mabits 传入参数为(Long, String, Integer)在mappe.xml文件中if判断时的坑
- 3、Determine whether an integer is a palindrome
- 009:How can I test if an array contains a certain value?
- How to tell if a file is an EXE or a DLL?
- How do you check if a variable is an array in JavaScript? [duplicate]
- Determine whether an integer is a palindrome. Do this without extra space.
- How to: Determine If a File Is an Assembly(From msdn)
- Determine if a String is a Number
- How do I add an integer value with javascript (jquery) to a value that's returning a string?
- Check if the key is composed of an arbitrary number of concatenations of strings from the dictionar