当前位置:七道奇文章资讯设计学堂DW设计
日期:2012-07-19 20:05:00  来源:本站整理

网页计划资源:网页表单考证常用代码例子[DW设计]

赞助商链接



  本文“网页计划资源:网页表单考证常用代码例子[DW设计]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>表单考证</title>
<script>
function $(id) {
return document.getElementById(id);
}
function checkUsername (username) {
var digital = /^\d+$/;
var character = /^\w+$/;
var elmt = $(‘user_error’);
if(username == null || username.length < 4){
elmt.innerHTML="用户名长度不能小于4个字符,请重新输入.";
return false;
}else if(username.length > 20){
$(‘user_error’).innerHTML="用户名长度不能大于20个字符,请重新输入.";
elmt.style.display=”;
return false;
}else if(digital.test(username)) {
$(‘user_error’).innerHTML="用户名不能为全数字,请重新输入.";
elmt.style.display=”;
return false;
}else if (!character.test(username)){
$(‘user_error’).innerHTML="用户名格局有误,请重新输入.";
elmt.style.display=”;
return false;
}else{
elmt.style.display="none";
return true;
}
}

function checkEmail1(id)
{
var rule = /^[0-9a-z]+[0-9a-z\-\._]*@[0-9a-z]+[0-9a-z\-]*(\.[a-z]{2,4}){1,2}$/i;
var obj = $(id);

if(obj.value == ""){
var msg = "请输入邮箱";
$(‘email_error’).innerHTML = msg;
$(‘email_error’).style.display="";
return false;
}

if(obj.value != "" && !rule.test(obj.value)){
var msg = "邮箱格局不精确.";
$(‘email_error’).innerHTML = msg;
$(‘email_error’).style.display="";
return false;
}else{
var msg = "邮箱填写精确";
$(‘email_error’).innerHTML = msg;
$(‘email_error’).style.display="";
return true;
}
}
function checkLevel(str)
{
var total_score = 0;
var length_score = checkLength(str);
var letter_score = checkLetter(str);
var digit_score = checkDigit(str);
var symbol_score = checkSymbol(str);

if (letter_score != 0 && digit_score != 0)
{
total_score += 2;
}

if (letter_score != 0 && digit_score != 0 && symbol_score != 0)
{
total_score += 3;
}

if (letter_score == 20 && digit_score != 0 && symbol_score != 0)
{
total_score += 5;
}

total_score += length_score + letter_score + digit_score + symbol_score;

if (total_score >= 90)
{
return 6;
}
else if (total_score >= 80)
{
return 5;
}
else if (total_score >= 70)
{
return 4;
}
else if (total_score >= 60)
{
return 3;
}
else if (total_score >= 50)
{
return 2;
}
else if (total_score >= 25)
{
return 1;
}
else
{
return 0;
}
}

function checkLength(str)
{
var score = 0;
if (str)
{
var length = str.length;
if (length <= 5)
{
score = 5;
}
else if (length > 5 && length <= 10) {
score = 10;
}
else
{
score = 25;
}
}

return score;
}

function checkLetter(str)
{
var score = 0;
if (str)
{
var rule1 = /^[^A-Z]*[a-z]+[^A-Z]*$|^[^a-z]*[A-Z]+[^a-z]*$/;
var rule2 = /^.*[a-z](.*[A-Z]{1,}.*)+$|^.*[A-Z](.*[a-z]{1,}.*)+$/;

if (rule1.test(str))
{
score = 10;
}
else if (rule2.test(str))
{
score = 20;
}
else
{
score = 0;
}
}

return score;
}

function checkDigit(str)
{
var score = 0;
if (str)
{
var rule1 = /^[^0-9]*([0-9][^0-9]*){1,2}$/;
var rule2 = /^[^0-9]*([0-9][^0-9]*){3,}$/;

if (rule1.test(str))
{
score = 10;
}
else if (rule2.test(str))
{
score = 20;
}
else
{
score = 0;
&nb
sp; }
}

return score;
}

function checkSymbol(str)
{
var score = 0
if (str)
{
var rule1 = /^[0-9a-z]*([^0-9a-z][0-9a-z]*){1}$/i;
var rule2 = /^[0-9a-z]*([^0-9a-z][0-9a-z]*){2,}$/i;

if (rule1.test(str))
{
score = 10;
}
else if (rule2.test(str))
{
score = 25;
}
else
{
score = 0;
}
}

return score;
}

function testLevel(id, str)
{

var level = checkLevel(str);

switch (level)
{
case 6: var status = "非常安全"; break;
case 5: var status = "安全"; break;
case 4: var status = "非常强"; break;
case 3: var status = "强"; break;
case 2: var status = "普通"; break;
case 1: var status = "弱"; break;
case 0: var status = "非常弱"; break;
default: var status = "";
}

var obj = $(id);
obj.innerHTML = status;
}

function checkRepassword(id, id2)
{
var obj = $(id);
var obj2 = $(id2);
var val = false;


if(obj2.value == "" || obj.value == ""){
var msg = "请输入密码!";
$(‘pwd_error’).innerHTML = msg;
$(‘pwd_error’).style.display="";
return false;
}

if (obj.value != obj2.value)
{
var msg = "两次输入的密码不一致,请重新输入.";
$(‘pwd_error’).innerHTML = msg;
$(‘pwd_error’).style.display="";
return false;
}
else
{
var msg = "密码符合要求";
$(‘pwd_error’).innerHTML = msg;
$(‘pwd_error’).style.display="";
return true;
}
}
</script>
</head>
<body>
<div>用户名:<input type="text" id="username" name="username" onkeyup="checkUsername(this.value);"/><input type="button" name="smt" value="检测" onclick="checkUsername(username.value);"/><span id="user_error" name="user_error"></span></div>
<div>邮箱:<input type="text" id="email" name="email" onkeyup="checkEmail1(‘email’);" /><input type="button" name="smt" value="检测" onclick="checkEmail1(‘email’);" /><span id="email_error" name="email_error"></span></div>
<div>密码:<input type="password" id="password" name="password" onkeyup="testLevel(‘safe’,this.value);checkRepassword(‘password’,'password2′);" />密码强度:<span id="safe" name="safe"></span>
<div>肯定密码:<input type="password" id="password2" name="password2" onkeyup="testLevel(‘safe’,password.value);checkRepassword(‘password’,'password2′)"/><input type="button" name="smt" value="检测" onclick="testLevel(‘safe’,password.value);checkRepassword(‘password’,'password2′)"/><span id="pwd_error" name="pwd_error"></span></div>
<div></div>
</body>
</html>
 

  以上是“网页计划资源:网页表单考证常用代码例子[DW设计]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
  • 网页计划标准总结:一套不错的网页制作标准
  • 网页计划资源:网页表单考证常用代码例子
  • CSS款式表在网页计划中的特点
  • <b>Dreamweaver网页计划制作本领与提高</b>
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .