表单验证,正则表达式的简单使用

28. December 2015 HTML5 0

function tests () {
if(document.getElementById(“input_name”).value.length<2){
document.getElementById(“lable1″).innerHTML=”名字至少要两个字哦!”;
}
else if(document.getElementById(“input_name”).value == “李健”){
document.getElementById(“lable1″).innerHTML=”该名字已被注册!”;
}
else if(document.getElementById(“input_name”).value == “lijian”){
document.getElementById(“lable1″).innerHTML=”该名字已被注册!”;
}
else{
document.getElementById(“lable1″).innerHTML=”恭喜你,该名字可以注册!”;
}

}

function test1 () {
var n = document.getElementById(“input_name1”).value;
var str = /d/;
if(str.test(n) && n.length<=11 && n.length>=6){
document.getElementById(“lable2″).innerHTML=”该手机号可以注册”;
}
else if (n==””){
}
else
document.getElementById(“lable2″).innerHTML=”请输入正确的手机号”;
}
function test2 () {
var n = document.getElementById(“input_name2”).value;
var str =/^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/
if(str.test(n)){
document.getElementById(“lable3″).innerHTML=”该电子邮箱可以注册”;
}
else if(n==””)
{
}
else{
document.getElementById(“lable3″).innerHTML=”请输入正确的电子邮箱”;
}
}
function test3 () {
var n=document.getElementById(“input_name3”).value;
var str=/[a-zA-Z][0-9]/
if(str.test(n)){
document.getElementById(“lable4″).innerHTML=”请牢记密码哦”;
}
else if(n==””){
}
else {
document.getElementById(“lable4″).innerHTML=”密码使用数字加密码组合哦”;
}
}


Leave a Reply

Your email address will not be published. Required fields are marked *