我得说清楚下:
判断文本框输入的只能是 数字\字母\汉字 ,不能有其它符号
也不能 数字\字母\汉字 都有,只能有一样.
判断文本框输入的只能是 数字\字母\汉字 ,不能有其它符号
也不能 数字\字母\汉字 都有,只能有一样.
解决方案 »
- 操作日志
- 求助啊!!!请各位大侠帮忙看看
- hibernate 更新页无法带入数据问题
- 求救:十万火急。The requested resource (/servlet/CommonServlet) is not available.
- 问一个连接数据库的方法.
- 大家帮我分析一下这是什么问题吧,我实在弄不懂了,谢了!!
- html表单里的
- !急, 如何用Servlet/JSP实现文件上载
- 请问在jsp中调用外部的类,与jsp调用javabean有何区别??
- tomcat 4.0 安装到 win2k下如何做...请教
- invalid operation for the current cursor position错误
- script标签src中的servlet程序不能执行?而<img>中的src却能执行
function check()
{
var regexp = /^(\d+|[a-zA-Z]+|[\u4E00-\u9FA5]+)$/;
var form = document.getElementById('aaa');
var value = form.bb.value;
if(!regexp.test(value))
{
alert("ok");
}
alert(value);
}
</script>
<body>
<form name="aaa">
input here:
<input type="text" name="bb">
<br>
<input type="button" value="click" onclick="check();">
</form>
</body>
如果你用java下,和二楼一样,也可以用同样的正则表达式.
<script type="text/javascript">
function check()
{
var obj = document.getElementById('bb');
if (obj == null) return false;
if (obj.value == "") return true;
var exp = new RegExp("^[\u4E00-\u9FA5\uF900-\uFA2D]*$");
if(exp.test(obj.value))
{
alert("yes");
} else{
alert("no");
}
alert(obj.value);
}
</script>
<body>
<form name="aaa">
input here:
<input type="text" name="bb">
<br>
<input type="button" value="click" onclick="check();">
</form> 根据你的需求中文、数字、英文只能包含一种,另两种一样的做法就行了。
至于汉字,你可能要利用汉字的双字节去判断。(一般字符单字节)。
/^[\u4e00-\u9fa5]$/汉字
/^[0-9]$/数字
/^[a-zA-Z]$/字母
Pattern p=Pattern.compile("正则表达式");Matcher m=p.matcher(a);
我输入什么都OK...我要求 数字/字母/汉字 只能有一样.
9楼的也不对
9楼的是不是判断 m.matchers()这个方法?每次都是false
String a="汉字";
Pattem p=Pattem.compile("/^[\u4e00-\u9fa5]$/");
Matcher m=p.matcher(a);
if(m.matchers()){
System.out.println("ok");
}
else{
System.out.println("不OK");
}
<script type="text/javascript">
function check()
{
var regexp = /^(\d+|[a-zA-Z]+|[\u4E00-\u9FA5]+)$/;
var form = document.getElementById('aaa');
var value = form.bb.value;
if(!regexp.test(value))
{
alert("ok");
}
alert(value);
}
</script>
<body>
<form name="aaa">
input here:
<input type="text" name="bb">
<br>
<input type="button" value="click" onclick="check();">
</form>
</body>
/**
* 判断一个字符是Ascill字符还是其它字符(如汉,日,韩文字符)
* @param c char 需要判断的字符
* @return boolean 返回true,Ascill字符
*/
public static boolean isLetter(char c) {
int k = 0x80;
return c / k == 0 ? true : false;
}