简单表单验证收藏
<script language=javascript>
function onlyEng()
{
if(!(event.keyCode>=65&&event.keyCode<=90))
event.returnValue=false;
}
function onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)))
//考虑小键盘上的数字键
event.returnValue=false;
}
function isEmail(strEmail) {
if (strEmail.search(/^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/) != -1)
return true;
else
alert("wrong");
}
</script>
只能是汉字:<input οnkeyup="value=value.replace(/[^/u4E00-/u9FA5]/g,'')"><br>
只能是英语字符:<input οnkeydοwn="onlyEng();"><br>
只能是数字:<input οnkeydοwn="onlyNum();"><br>
只能是英文字母和数字:<input οnkeyup="value=value.replace(/[/W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"><br>
验证email格式:<input type=text οnblur=isEmail(this.value)><br>
不能输入汉字<INPUT οnpaste="return false;" style="IME-MODE: disabled; WIDTH: 400px" value="I only accept English input! Thanks for corporation!" name=textfield><br>
<script language=javascript>
function onlyEng()
{
if(!(event.keyCode>=65&&event.keyCode<=90))
event.returnValue=false;
}
function onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)))
//考虑小键盘上的数字键
event.returnValue=false;
}
function isEmail(strEmail) {
if (strEmail.search(/^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/) != -1)
return true;
else
alert("wrong");
}
</script>
只能是汉字:<input οnkeyup="value=value.replace(/[^/u4E00-/u9FA5]/g,'')"><br>
只能是英语字符:<input οnkeydοwn="onlyEng();"><br>
只能是数字:<input οnkeydοwn="onlyNum();"><br>
只能是英文字母和数字:<input οnkeyup="value=value.replace(/[/W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"><br>
验证email格式:<input type=text οnblur=isEmail(this.value)><br>
不能输入汉字<INPUT οnpaste="return false;" style="IME-MODE: disabled; WIDTH: 400px" value="I only accept English input! Thanks for corporation!" name=textfield><br>