表单验证必须为6-12位英文字母去除首尾空格

Posted on 2015-04-23 11:34  小蕊同学  阅读(345)  评论(0编辑  收藏  举报
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>网站首页</title>
    <style>

    </style>
</head>

<body>
<form action="save.php" method="post" onSubmit="return check()">
账号:<input type="text" id="account" name="account">
<input type="submit" value="提交">  
</form>
</body>
</html>
<script>
function $(id){
    return document.getElementById(id);
}
String.prototype.trim =function(){
    return this.replace(/^\s+|\s+$/g,'');    
}
function check(){
    var aa=$('account');
    var ac=aa.value.trim();
    aa.value=ac;
    var p=/^[a-z]{6,12}$/i;
    if(!p.test(ac)){
        alert('账号必须为6-12位英文字母');
        aa.focus();
        return false;
    }

return true;
}




    
</script>

 

Copyright © 2024 小蕊同学
Powered by .NET 9.0 on Kubernetes