HTML5注册页面示例代码,密码强度验证

概况样式: 

var reg=/正则表明式/;
boolean reg.test(要证明的字符串);
js引擎会将/正则表达式/ 转变来一个RegExp对象,当字符串知足正则表达式的要求事,重临true。
本身写的七个表明式验证示例:功效如下:
客商名,不可能为空
密码6为数字
密码确认,四回输入密码必需一律
身份ID编号不可能不是13人,或许是二十一人,最末尾也足以是X(该功能还一直不写,有的时候光再补上)

点评:HTML5写的登记页面,正在攻读html5的恋人能够参照下

图片 1
源码:

复制代码 代码如下:

代码如下:

复制代码 代码如下:

<!DOCTYPE html>
<html>
<head>
<title>testTablel.html</title>
<!-- 顾客名,不能够为空
密码6为数字
密码确认,一次输入密码必得一律
身份ID编号不可能不是14个人,只怕是19人,最末尾也得以是X -->
<style>
#d1 {
width: 400px;
height: 250px;
background-color: #FFE4B5;
margin: 40px auto;
}
#d1_head {
color: white;
font-size: 20px;
font-family: "Arial";
height: 24px;
background-color: bule;
}
#d1_content {
padding-left: 30px;
padding-top: 30px;
}
.s1 {
color: red;
font-style: italic;
}
.s2 {
border: 2px dotted blue;
}
</style>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
function check_username(){
var txtObj=document.getElementById("username");
txtObj.className='';
var msgObj=docuemnt.getElementById("username_msg");
msgObj.innerHTML='';
if(txtObj.value.length==0){
msgObj.innerHTML='客商名无法为空';
//给节点的class属性赋值
txtObj.className='s2';
return false;
}
return true;
}
function check_pwd(){
var pwdObj=document.getElementById("pwd");
pwdObj.classNames='';
var msgObj=document.getElementById("pwd_msg");
msgObj.innerHTML='';
var reg=/^d{6}$/;
//javascript中一个test方法,返回boolean
if(!reg.test(pwdObj.value)){
msgObj.innerHTML='密码是6位数';
pwdObj.className='s2';
return false;
}
return true;
}
function check_pwd1(){
var pwdObj=document.getElementById("pwd");
// pwdObj.classNames='';
// var msgObj=document.getElementById("pwd_msg");
// msgObj.innerHTML='';
var pwdObj1=document.getElementById("pwd1");
//pwdObj1.classNames='';
var msgObj1=document.getElementById("pwd_msg1");
msgObj1.innerHTML='';
if(pwdObj.value!=pwdObj1.value){
msgObj1.innerHTML='密码不雷同,请重新输入';
return false;
}
return true;
}
function check_form(){
var flag=check_username()&&check_pwd()&&check_pwd1;
return flag;
}
</script>
</head>
<body>
<div id="d1">
<div id="d1_head">注册</div>
<div id="d1_content">
<form onsubmit="return check_form();">
<table>
<tr>
<td>用户名</td>
<td><input id="username" name="username"
onblur="check_username();" /> <span class="s1" id="username_msg"></span>
</td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" id="pwd" name="pwd"
onblur="check_pwd();" /> <span class="s1" id="pwd_msg"></span></td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="password" id="pwd1" name="pwd1"
onblur="check_pwd1();" /> <span class="s1" id="pwd_msg1"></span>
<tr>
<td colspan="2">
<input type="submit" value="确认" /> <input type="reset"
value="重置" />
</td>
</tr></table>
</form>
</div>
</div>
</body>
</html>

<!DOCTYPE html>
<html>
<head>
<title>register.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<LINK rel="Shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="css/register.css" />
<script src="js/checkbox.js" type="text/javascript">
</script>
<script type="text/javascript">
function play(){
document.getElementById("menu_item").style.display = "";
}
function noplay(){
document.getElementById("menu_item").style.display = "none";
}
function passwd(){
var pass = document.getElementById("password").value;
var tip = document.getElementById("tip");
if (pass.length < 4) {
document.getElementById("meter").value = pass.length;
tip.innerHTML = "差";
}
else
if (pass.length <= 8) {
document.getElementById("meter").value = pass.length;
tip.innerHTML = "中";
}
else {
document.getElementById("meter").value = pass.length;
tip.innerHTML = "高";
}
}
</script>
</head>
<body>
<div id="3" style="position: relative; top: 100px; z-index: 3;">
<form id="f1" action="register.html" method="post">
<table align="center" cellspacing="0" class="table">
<tr class="thead">
<td align="center">
会员注册
</td>
</tr>
<tr>
<td>
<table id="registertable" border="0px" align="center" border="0px" cellspacing="0" cellpadding="5px">
<tr>
<tr>
<td align="right">
职工编号:
</td>
<td align="left">
<input type="text" name="username" placeholder="用户名" required/>
</td>
</tr>
<tr>
<td align="right">
密 码:
</td>
<td align="left">
<input type="password" name="password" id="password" placeholder="密码" required onkeyup="passwd()"/>
<meter min="1" max="10" low="5" high="8" value="0" id="meter">
</meter>
<span id="tip"></span>
</td>
</tr>
<tr>
<td align="right">
密码确认:
</td>
<td align="left">
<input type="password" name="password2" placeholder="确认密码" required/>
</td>
</tr>
<tr>
<td align="right">
生 日:
</td>
<td align="left">
<input type="date" name="borthday" />
</td>
</tr>
<tr>
<td align="right">
性 别:
</td>
<td align="left">
<input type="radio" name="gender" value="0" checked/>男
<input type="radio" name="gender" value="1"/>女
</td>
</tr>
<tr>
<td align="right">
邮 箱:
</td>
<td align="left">
<input type="email" name="email" placeholder="邮箱" id="email" required/>
</td>
</tr>
<tr>
<td align="right">
手 机:
</td>
<td align="left">
<input type="tel" pattern="[0-9]{11}" id="p" name="phone" placeholder="请输入11位数字" />
</td>
</tr>
<tr>
<td align="right">
地 址:
</td>
<td align="left">
<input type="text" name="address" placeholder="地址" list="l"/>
<datalist id="l">
<option value="sh">上海</option>
<option value="bj">北京</option>
<option value="js">江苏</option>
<option value="zz">郑州</option>
<option value="sz">深圳</option>
</datalist>
</td>
</tr>
<tr>
<td align="right">
村办网页:
</td>
<td align="left">
<input type="url" name="page" placeholder="主页网站" />
</td>
</tr>
<tr>
<td align="right">
起来时间:
</td>
<td align="left">
<input type="time" name="bed" onblur="pro()"/>
</td>
</tr>
<tr>
<td align="right">
头像:
</td>
<td align="left">
<input type="file" id="f" accept="image/jpeg" onchange="show()"/><span><img id="img" src="" width="60" height="60" /></span>
<script>
function show(){
var file = document.getElementById("f").files[0];
var fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = function(){
document.getElementById("img").src = fileReader.result;
}
}
</script>
</td>
</tr>
<tr>
<td colspan="2">
<details>
<p>
同意注册
<mark>
许可证
</mark>信息
</p>
<summary>
挂号许可音讯
</summary>
</details>
</td>
</tr>
<tr>
<td align="right">
验证码:
</td>
<td valign="middle">
<input type="text" name="captcha" size="11" maxlength="4" title="输入左侧的验证码" />
<span id="span"></span>
<script>
var span = document.getElementById("span");
span.innerHTML=Math.floor(Math.random());
</script>
</td>
</tr>
<tr height="60px">
<td align="center" colspan="2">
<input type="button" value="转到登入" onclick="window.location.replace('login.html')" id="btn1" onmousemove="changeBgColor('btn1')" onmouseout="recoverBgColor('btn1')" class="submit" /> <input type="submit" accesskey="enter" value="注册" id="btn" onmousemove="changeBgColor('btn')" onmouseout="recoverBgColor('btn');" class="submit" formmethod="post"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

//=================HTML页面=================
<body onload="InitCss();">
<form>
<div>
<table>
<tr>
<td>
密码:
</td>
<td>
<input id="txtPassword" type="password" style="width: 130px;" maxlength="16" onfocus="InitCss();"
onblur="ValidateInput('password',this.value)" onkeydown="validatePwdStrong(this.value);" />
</td>
<td>
<div id="tipPosition">
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<table id="pwdStrong_color">
<tr>
<td id="pwdStrong_1">
</td>
<td id="pwdStrong_2">
</td>
<td id="pwdStrong_3">
</td>
<td id="pwdStrong_4">
</td>
</tr>
</table>
</td>
<td>
<div id="pwdStrong_text">
</div>
</td>
</tr>
</table>
</div>
</form>
</body>

代码如下:

JS文件

body {
background-image: url("../images/bg.jpg");
text-align: center;
background-repeat: repeat-x;
background-position: 0px 0px ;
background-size:
}
.table {
border: 1px solid #90BFFF;
width:810px;
}
tr {
font-family: 微软雅黑;
font-weight:800;
color: #448EF3;
}
input{
border: 1px solid #448EF3;
color: #448EF3;
font-weight:bold;
font-family: "微软雅黑";
height: 35px;
line-height: 30px;
border-radius:5px;
}
.submit {
width: 150px;
height: 40px;
cursor :hand;
font-size: 20px;
color: #ffffff;
background-color: #448EF3;
border: 0px;
}
.thead {
height: 40px; background : #90BFFF;
font-family: "微软雅黑";
font-size: 30px;
font-weight: 700;
color: #ffffff;
background: #90BFFF;
}
#3{
margin-bottom: 100px;
}

复制代码 代码如下:

代码如下:

//使用$替换document.getElementById函数
var $ = function(v) { return document.getElementById(v); }

function ChkAllClick(sonName, cbAllId){
var arrSon = document.getElementsByName(sonName);
var cbAll = document.getElementById(cbAllId);
var tempState=cbAll.checked;
for(i=0;i<arrSon.length;i ) {
if(arrSon[i].checked!=tempState)
arrSon[i].click();
}
}
function ChkSonClick(sonName, cbAllId) {
var arrSon = document.getElementsByName(sonName);
var cbAll = document.getElementById(cbAllId);
for(var i=0; i<arrSon.length; i ) {
if(!arrSon[i].checked) {
cbAll.checked = false;
return;
}
}
cbAll.checked = true;
}
function ChkOppClick(sonName){
var arrSon = document.getElementsByName(sonName);
for(i=0;i<arrSon.length;i ) {
arrSon[i].click();
}
}
function changeBgColor(btn){
var btn = document.getElementById(btn);
btn.style.backgroundColor = "#90BFFF"
}
function recoverBgColor(btn){
var btn = document.getElementById(btn);
btn.style.backgroundColor = "#448EF3"
}

/******************************************************表达客商输入******************************************************/
function ValidateInput(element, value) {
//验证密码
if (element == "password") {
if (value.toString().length < 6) {
$('tipPosition').className = 'error';
$('tipPosition').innerHTML = "密码设置错误。密码长度过小。";
return;
}
else {
$('tipPosition').className = 'success';
$('tipPosition').innerHTML = "填写正确。";
}
}
}
/*================================密码验证JS =========== Begin=======================================*/
//密码早先化的体制
function InitCss() {
$('tipPosition').className = 'tip';
$('tipPosition').innerHTML = "最小长度:6。 最大尺寸:16。";
}


/*================================密码强度 ===========Begin=======================================*/

下面文件的各类是:register.html register.css checkbox..js

function Evaluate(word) {
return word.replace(/^(?:([a-z])|([A-Z])|([0-9])|(.)){5,}|(.) $/g, "$1$2$3$4$5").length;
}


function validatePwdStrong(value) {
var pwd = {
color: ['#E6EAED', '#AC0035', '#FFCC33', '#639BCC', '#246626'],
text: ['太短', '弱', '一般', '很好', '极佳']
};
function colorInit() {
$('pwdStrong_1').style.backgroundColor = pwd.color[0];
$('pwdStrong_2').style.backgroundColor = pwd.color[0];
$('pwdStrong_3').style.backgroundColor = pwd.color[0];
$('pwdStrong_4').style.backgroundColor = pwd.color[0];
}
if (Evaluate(value) == 1) {
colorInit();
$('pwdStrong_1').style.backgroundColor = pwd.color[1];
$('pwdStrong_text').innerHTML = pwd.text[1];
$('pwdStrong_text').style.color = pwd.color[1];
}
else if (Evaluate(value) == 2) {
colorInit();
$('pwdStrong_1').style.backgroundColor = pwd.color[2];
$('pwdStrong_2').style.backgroundColor = pwd.color[2];
$('pwdStrong_text').innerHTML = pwd.text[2];
$('pwdStrong_text').style.color = pwd.color[2];
}
else if (Evaluate(value) == 3) {
colorInit();
$('pwdStrong_1').style.backgroundColor = pwd.color[3];
$('pwdStrong_2').style.backgroundColor = pwd.color[3];
$('pwdStrong_3').style.backgroundColor = pwd.color[3];
$('pwdStrong_text').innerHTML = pwd.text[3];
$('pwdStrong_text').style.color = pwd.color[3];
}
else if (Evaluate(value) == 4) {
$('pwdStrong_1').style.backgroundColor = pwd.color[4];
$('pwdStrong_2').style.backgroundColor = pwd.color[4];
$('pwdStrong_3').style.backgroundColor = pwd.color[4];
$('pwdStrong_4').style.backgroundColor = pwd.color[4];
$('pwdStrong_text').innerHTML = pwd.text[4];
$('pwdStrong_text').style.color = pwd.color[4];
}
}

背景图片:bg.jpg

//=================CSS文件=================

图片 2

复制代码 代码如下:

body
{
font: 13px 宋体;
}
/*密码验证提醒CSS --------------------------------开端--------------------------------*/
#tipPosition
{
width: 400px;
height: 16px;
line-height: 18px;
padding: 2px 30px;
}
.tip
{
background: #E6F2FF url(images/register_tip.png) no-repeat 10px center;
border: 1px #0E5863 dashed;
color: #0E5863;
}
.error
{
background: #FBECDF url(images/register_error.png) no-repeat 10px center;
border: 1px Red dashed;
color: #6D3737;
}
.success
{
background: #D6FCD2 url(images/register_success.png) no-repeat 10px center;
border: 1px #2F5D36 dashed;
color: #3D934A;
}
/*密码强度CSS --------------------------------起始--------------------------------*/
#pwdStrong_color
{
width: 136px;
height: 3px;
border: 0px;
border-collapse: collapse;
border-spacing: 0;
background: #E6EAED;
margin-top: 5px;
}
#pwdStrong_color td
{
padding: 0px;
width: 44px; /*如不加td宽度,Google的Chrome不会健康显示*/
}
#pwdStrong_text
{
font: 12px 宋体;
}

: 源码: 复制代码 代码如下: //=================HTML页面================= body onload="InitCss();" form div table tr td 密码: /td td input id="txtPassword"...

本文由星彩网app下载发布于前端技术,转载请注明出处:HTML5注册页面示例代码,密码强度验证

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。