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

<!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>
原文地址:https://www.cnblogs.com/lsr111/p/4449944.html