刘建广

博客园 首页 联系 订阅 管理

String str1 = "123456";
// 判断是否为数字
Pattern pattern = Pattern.compile("[0-9]*");
if(pattern.matcher(str1).matches()==false){
System.out.println("你输入的不是数字,请重新检查");
}else{
System.out.println("你输入的为数字");
}

 

input 标签 判断 不能输入汉字

<input name="textfield" id="textfield" type="text" class="STYLE1" style="height:16px; width:25px;" size="5" onkeyup="value=value.replace(/[^\d]/g,'')" maxlength="9"/>

此判断 有一bug (这个方法不推荐,有一种操作可以在input中输入汉字),如果想使用的话,必须后续判断input

posted on 2013-01-28 11:06  刘建广  阅读(1127)  评论(0编辑  收藏  举报