首页 > 其他 > 详细

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

时间:2015-04-23 12:23:40      阅读:72      评论:0      收藏: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>

 

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

原文:http://www.cnblogs.com/lsr111/p/4449944.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!