这个你看看吧,应该是你想要的东西吧
<html>
<body>
<script language="javascript">
function suba(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(o.value.charCodeAt(i)<65||o.value.charCodeAt(i)>90)
{
window.alert("只能输入大写字母")
o.focus();
o.value="";
break;
}
}
}function subb(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(o.value.charCodeAt(i)<97||o.value.charCodeAt(i)>122)
{
window.alert("只能输入小写字母")
o.focus();
o.value="";
break;
}
}
}function subc(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(o.value.charCodeAt(i)<48||o.value.charCodeAt(i)>57)
{
window.alert("只能输入数字")
o.focus();
o.value="";
break;
}
}
}function subd(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(!((o.value.charCodeAt(i)>=48&&o.value.charCodeAt(i)<=57)||(o.value.charCodeAt(i)>=65&&o.value.charCodeAt(i)<=90)||(o.value.charCodeAt(i)>=97&&o.value.charCodeAt(i)<=122)))
{
window.alert("只能输入字母或数字")
o.focus();
o.value="";
break;
}
}
}function sube(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(o.value.charCodeAt(i)<65||o.value.charCodeAt(i)>90||o.length<3||o.length>3)
{
window.alert("只能输入三位大写字母")
o.focus();
o.value="";
break;
}
}
}function subf(o)
{
if(o.value.length<3||o.value.length>3)
{
window.alert("只能输入三位")
o.focus();
o.value="";
}
}
</script><form name="abc">
<input type=text name=a>
<input type=button value=只能输入大写字母 onclick="suba(abc.a)">
<input type=button value=只能输入小写字母 onclick="subb(abc.a)">
<input type=button value=只能输入数字 onclick="subc(abc.a)">
<input type=button value=只能输入数字和字母 onclick="subd(abc.a)">
<input type=button value=只能输入三位大写字母 onclick="sube(abc.a)">
<input type=button value=只能输入三位 onclick="subf(abc.a)">
</form>
</body>
</html>
<html>
<body>
<script language="javascript">
function suba(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(o.value.charCodeAt(i)<65||o.value.charCodeAt(i)>90)
{
window.alert("只能输入大写字母")
o.focus();
o.value="";
break;
}
}
}function subb(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(o.value.charCodeAt(i)<97||o.value.charCodeAt(i)>122)
{
window.alert("只能输入小写字母")
o.focus();
o.value="";
break;
}
}
}function subc(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(o.value.charCodeAt(i)<48||o.value.charCodeAt(i)>57)
{
window.alert("只能输入数字")
o.focus();
o.value="";
break;
}
}
}function subd(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(!((o.value.charCodeAt(i)>=48&&o.value.charCodeAt(i)<=57)||(o.value.charCodeAt(i)>=65&&o.value.charCodeAt(i)<=90)||(o.value.charCodeAt(i)>=97&&o.value.charCodeAt(i)<=122)))
{
window.alert("只能输入字母或数字")
o.focus();
o.value="";
break;
}
}
}function sube(o)
{
var i=0
for(i=0;i<o.value.length;i++)
{
if(o.value.charCodeAt(i)<65||o.value.charCodeAt(i)>90||o.length<3||o.length>3)
{
window.alert("只能输入三位大写字母")
o.focus();
o.value="";
break;
}
}
}function subf(o)
{
if(o.value.length<3||o.value.length>3)
{
window.alert("只能输入三位")
o.focus();
o.value="";
}
}
</script><form name="abc">
<input type=text name=a>
<input type=button value=只能输入大写字母 onclick="suba(abc.a)">
<input type=button value=只能输入小写字母 onclick="subb(abc.a)">
<input type=button value=只能输入数字 onclick="subc(abc.a)">
<input type=button value=只能输入数字和字母 onclick="subd(abc.a)">
<input type=button value=只能输入三位大写字母 onclick="sube(abc.a)">
<input type=button value=只能输入三位 onclick="subf(abc.a)">
</form>
</body>
</html>
function checkDig( id )
{
//alert("in checkDig");
var component =document.getElementById("num"+id);
var myvalue = component.value;
if( isNaN( myvalue ) ){
alert("申请数量只能是数字,请重新输入");
component.value="1";
component.select();
component.focus();
this.ret =1 ;
}else{
this.ret = 0 ;
}}
服务器端: content 为输入的内容
Pattern p = Pattern.compile("^\d+$");
Matcher m = p.matcher(cellText);
if(!m.find())system.out.println("the content for input is not date");
客户端:用js
if(!content.match("/^\d+$/"))alert("the content for input is not date");
长度很简单,不用我说了吧:)
解吸这个简单的正则表达式:^\d+$
1: ^表示开头是什么字符
2: \d表示0到9的数字
3: + 表示其修饰的字符出现一次或多次
4: $表示以什么结尾
上面连起来就是以0到9任何数字开头,中间可以出现最少一次的任意的0到9之间数字,并且以之结尾
function isNum(ch)
{
if(ch >= '0' && ch <= '9')return true;
return false;
}function isAllNum(str1)
{
for (i=0; i<str1.length; i++) {
if (!isNum(str1.charAt(i)))
{
return false;
}
}
return true;
}
这两个js函数就可以了
var myReg=/^\d*$/;
if(!myReg.test(value)){
alert("请输入数字");
}
}
长度可以用 var length = component.value.length取得验证是否是数字可以用 wudouguerwxx(家有小熊)的正则表达式判断好运!
alert("请输入数字");
}
}