`
ladymaidu
  • 浏览: 680015 次
文章分类
社区版块
存档分类
最新评论

test if a string is an integer?

 
阅读更多

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

分享到:
评论

相关推荐

    2009 达内Unix学习笔记

    [] 匹配中括号里的内容[a-z][A-Z][0-9]。 ! 事件。 $ 取环境变量的值。 | 管道。把前一命令的输出作为后一命令的输入,把几个命令连接起来。 |经常跟tee连用,tee 把内容保存到文档并显示出来。 三、通用后...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    (One exception is if an argument Foo or const Foo& has a non-explicit, one-argument constructor, in which case we need the full definition to support automatic type conversion.) We can declare ...

    微软内部资料-SQL性能优化3

    If a page is locked, SQL Server will apply an intent lock at the table level. SIX locks imply that we have shared access to a resource and we have also placed X locks at a lower level in the ...

    Turbo C++ 3.0[DISK]

    the compiler will search for test.cpp, and give an error if a file of that name cannot be found. If you want to have the command-line compiler assume a .c extension and C language source, use the ...

    Turbo C++ 3.00[DISK]

    the compiler will search for test.cpp, and give an error if a file of that name cannot be found. If you want to have the command-line compiler assume a .c extension and C language source, use the ...

    occam一维反演

    C BE A DUMMY ROUTINE IF SYSTEM PROGRAMMING IS TOO MUCH. C INPUTD(FILENAME), TAKES THE NAMED FILE AND USES IT TO GET THE DATA IMAGE INTO C THE COMMON BLOCK /DATA/. SEE OCCAM HEADER. C INPUTM(FILENAME)...

    Chinese Entity Linking Comprehensive

    If there is a matching node for a query, annotators create a link between the two. If there is not a matching node for a query, the entity is marked as 'NIL' and then clustered with other NIL ...

    Senfore_DragDrop_v4.1

    Delphi's THandle type when a HWND is passed to a function. E.g.: if (DragDetectPlus(THandle(MyControl-&gt;Handle), Point(X, Y))) { ... } * Virtual File Stream formats can only be pasted from the ...

    acpi控制笔记本风扇转速

    Fixed a regression where an error was no longer emitted if a control method attempts to create 2 objects of the same name. This once again returns AE_ALREADY_EXISTS. When this exception occurs, it ...

    Java大学教程

    // a menu driven program to test a selection of useful array methods public class SomeUsefulArrayMethods { public static void main (String[] args) { char choice; Scanner sc = new Scanner(System....

    libtomcrypt-1.17

    ASN.1 DER for SEQUENCE, INTEGER, BIT STRING, OCTET STRING, OBJECT IDENTIFIER, IA5 STRING, PRINTABLE STRING, UTCTIME, CHOICE and NULL types. Portable code builds out of the box with a conforming C ...

    jsp网上投票系统myeclipse开发

    * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server ...

    BIND-LINUX64位包

    does not exist or is not a directory. [RT #35108] Added improvements to statistics channel XSL stylesheet: the stylesheet can now be cached by the browser; section headers are omitted from the ...

    Git-2.21.0-64-bit.zip

    * A test helper has been introduced to optimize preparation of test repositories with many simple commits, and a handful of test scripts have been updated to use it. Fixes since v2.22 -----------...

    ZendFramework中文文档

    Querying if the input is valid 14.5.3.2. Getting Invalid, Missing, or Unknown Fields 14.5.3.3. Getting Valid Fields 14.5.4. Using Metacommands to Control Filter or Validator Rules 14.5.4.1. The ...

    jQuery完全实例.rar

    Additionally, the function, when executed, is passed a single argument representing the position of the element in the matched set (integer, zero-index). Returning 'false' from within the each ...

    From C to C++

    // convert a string to uppercase! #include #define N 200 int main(){ char ms[N]; int i; printf("Input ms: "); gets(ms); for(i=0;ms[i];i++) if(ms[i]&gt;='a'&&ms[i]) ms[i]-='\x20'; puts(ms); ...

    雷达技术知识

    glance the water surface at angles of incidence greater than 53 degrees, a LiDAR pulse is 2 more often lost to refraction (Figure 2) (Jenkins, 1957). In broken water surface conditions the water ...

    ViewPager 放大缩小左右移动

    * Indicates that the pager is in an idle, settled state. The current page * is fully in view and no animation is in progress. */ public static final int SCROLL_STATE_IDLE = 0; /** * ...

    testActiveMQ.rar

    * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing ...

Global site tag (gtag.js) - Google Analytics