日期:2014-05-16 浏览次数:20471 次
<input type="text" id="itext" /><input type="button" value="测试" onclick="test()" /> <script language="JavaScript" type="text/javascript" > function test() { var reg = /^\w+$/; var val = document.getElementById("itext").value; if(val!="") { alert(reg.test(val)); } } </script>
------解决方案--------------------
function checkUserName(){
try{
usernameObj = document.loginform.username;
username_re=/(\d|[a-z]|_)+/;
if(! username_re.test(usernameObj.value)){
alert("用户名格式不正确!");
usernameObj.focus();
return false;
}
}catch(exception){
alert("Make sure the object id is correct!");
return false;
}
return true;
}
------解决方案--------------------
<input type="text" id="itext" /><input type="button" value="测试" onclick="test()" />
<script language="JavaScript" type="text/javascript" >
function test()
{
var reg = /^\w+$/;
var val = document.getElementById("itext").value;
if(val!="")
{
alert(reg.test(val));
}
}
</script>