萍聚社区-德国热线-德国实用信息网

 找回密码
 注册

微信登录

微信扫一扫,快速登录

萍聚头条

查看: 605|回复: 0

1-1-19-5 判断String是否数字

[复制链接]
发表于 2003-2-7 02:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册 微信登录

x
发信人: ioly (anguls), 信区: Java      
标  题: Re: String问题!
发信站: BBS 水木清华站 (Mon May 27 22:48:47 2002)

jdk1.4的新特性


  1. import java.util.regex.Pattern;
  2. import java.util.regex.Matcher;
  3. public class NumberOnly{
  4. public static void main(String[] args){
  5.   Pattern p = Pattern.compile("^\\d+$");
  6.   String[] test_list = {
  7.    "",
  8.    "12asDFasdf",
  9.    "#$%$#ASdfasdf1023",
  10.    "测试字符串",
  11.    "\r\n\t1231231",
  12.    "1231231",
  13.    null,
  14.   };
  15.   for(int i = 0, len = test_list.length;i < len;i++){
  16.    System.out.println(""" + test_list[i] + "" is number only? "
  17.                       + p.matcher(test_list[i]).matches());
  18.   }
  19. }
  20. }
复制代码


【 在 worldeye (人狂) 的大作中提到: 】
: 如何判断,一个输入的String是数字,不是其他字符
: 在Jsp提交表单中使用的!
Die von den Nutzern eingestellten Information und Meinungen sind nicht eigene Informationen und Meinungen der DOLC GmbH.
您需要登录后才可以回帖 登录 | 注册 微信登录

本版积分规则

手机版|Archiver|AGB|Impressum|Datenschutzerklärung|萍聚社区-德国热线-德国实用信息网 |网站地图

GMT+2, 2024-6-14 23:13 , Processed in 0.057141 second(s), 19 queries , MemCached On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表