jquery 註冊驗證

:oops:
funCheck[0] = function(str) { //帳號
if (isNotNull(str))
{ return 0; }
else { return 1; }
}
funCheck[1] = function(str) { //暱稱
if (isNotNull(str)) {
return 0;
}
else { return 1; }
}
funCheck[2] = function(str) { //email
if (isEmail(str))
{ return 0; }
else { return 1; }
}
funCheck[3] = function(str) { //聯繫電話
if (isTel(str) || isPhone(str))
{ return 0; }
else { return 1; }
}
//--------
funCheck[4] = function(str) { //密碼
if (isNotNull(str))
{ return 0; }
else { return 1; }

}

funCheck[5] = function(str) { //確認密碼
if (isNotNull(str)) {
if ($("#passwd1").val() == $("#passwd2").val()) {
return 0;
} else {
return 2;
}
}
else { return 1; }
}
funCheck[6] = function(str) { //密碼提示問題
if (str == null || str == "") { return 1; } else {
if (isSmall(str, 20)) { return 0; }
else { return 2; }
}
}
funCheck[7] = function(str) { //密碼提示答案
if (str == null || str == "") { return 1; } else {
if (isSmall(str, 20)) { return 0; }
else { return 2; }
}
}
//------------
funCheck[8] = function(str) { //真實姓名

return 0;
}
funCheck[9] = function(str) { //年齡
if (str == "" || str == null) { return 0; }
if (str > 0 && str < 100) { return 0; } else { return 1; }
}
funCheck[10] = function(str) { //個人主頁
return 0;
}
funCheck[11] = function(str) { //qq
return 0;
}
funCheck[12] = function(str) {//簡介
if (isSmall(str, 100))
{ return 0; }
else { return 1; }
}


$(document).ready(function() {
var uid = false;

/*這個部分是實現選擇不同的輸入的時候,顯示不同的提示信息*/
$(".text_01").focus(function() {
// alert($(this).parent().next("div").attr("class"));
$(this).parent().next("div").html(msgInfo[$(".text_01").index($(this)[0])][0]);
$(this).parent().next("div").removeClass();
$(this).parent().next("div").addClass("tips2");
});
$(".text_01").blur(function() {
//alert($(this).parent().next().html());

$(this).parent().next("div").html("");
$(this).parent().next("div").removeClass();
//alert($(this).attr("id"));
if ($(this).attr("id") == "usrname") {

if (isNotNull(this.value)) {//如果用戶名不爲空
if (isSmall(this.value, 6))//如果用戶名小於6位
{
$(this).parent().next("div").removeClass();
$(this).parent().next("div").addClass("wrong");
$(this).parent().next("div").html("<img src='../img/zhaoshang2/zhao2_06.gif' border='0' />" + msgInfoUID[4]);
// $(this).parent().next("div").html(msgInfoUID[4]);

uid = false;

}
else {
if (isUID(this.value)) {
var flag = 0;
//alert(1);
var murl = "../ashx/RegisterCheck.ashx?&name=" + encodeURI($("#usrname").val());
$.ajax(
{
type: "GET",
url: murl,
data: "",
//async:false,//同步請求,只有請求完成之後才能進行其他操作
success: function(result) {

var isUsed = result;
//alert(isUsed);
if (isUsed == "false") {//可以註冊
//alert("可以註冊");
$($("#usrname")).parent().next("div").removeClass();
$($("#usrname")).parent().next("div").html(msgInfoUID[3]);
$($("#usrname")).parent().next("div").addClass("right");
uid = true;
//alert(isUsed);
}
else {//用戶名已經被註冊
//alert("用戶名已經被註冊");
//alert($(".text_01").index($(this)[0]));
$($("#usrname")).parent().next("div").removeClass();
$($("#usrname")).parent().next("div").addClass("wrong");
$($("#usrname")).parent().next("div").html("<img src='../img/zhaoshang2/zhao2_06.gif' border='0' />" + msgInfoUID[2]);
//alert($(this).parent().next("div").attr("class"));
// alert($(this).html());
uid = false;
}
}
});

}
else {
//alert(2);
$($("#usrname")).parent().next("div").removeClass();
$($("#usrname")).parent().next("div").html(msgInfoUID[0]);
$($("#usrname")).parent().next("div").addClass("wrong");
uid = false;
}
}
}
else {
// alert(3);
$($("#usrname")).parent().next("div").removeClass();
$($("#usrname")).parent().next("div").html(msgInfoUID[1]);
$($("#usrname")).parent().next("div").addClass("wrong");
uid = false;
}

}
if (funCheck[$(".text_01").index($(this)[0])]($(this)[0].value) == 0) {
//alert(4);
if ($(".text_01").index($(this)[0]) != 0 && $(".text_01").index($(this)[0]) != -1) {

//alert(5);
$(this).parent().next("div").removeClass("wrong");
$(this).parent().next("div").removeClass("tips2");
}
}
else {
//alert(2);
///alert($(".text_01").index($(this)[0]));
$(this).parent().next("div").html("<img src='../img/zhaoshang2/zhao2_06.gif' border='0' />" + msgInfo[$(".text_01").index($(this)[0])][funCheck[$(".text_01").index($(this)[0])]($(this)[0].value)]);
$(this).parent().next("div").addClass("wrong");

}
//alert(funCheck[$(".kinput").index($(this)[0])]($(this)[0].value));
});

/*是否存在驗證*/


$("#submit_butt").click(function() {//點擊報錯的時候,驗證數據是不是全部合法,如果全部合法,則提交,否則return false;
var isCheck = true;
// alert(0);

$(".text_01").each(function(j) {
if (j <= 7)
$($(".text_01").get(j)).blur();
});
$(".wrong").each(function(i) {
isCheck = false;
});
// if ($("#usrname").val() == "") {
// isCheck = false
// }
if (isCheck == false) {
alert("請按照要求填寫帶(*)號的項");
}

return isCheck;
})
// $(document).click(function() {
//// $("#wrap").show(5000);
//// $("#wrap").fadeOut(1000);
// })
})
</script>

</form>
</body>
</html>
<script language="javascript" type="text/javascript" src="../JS/check.js"></script> 這個文件如下


/*
限制輸入字符的位數
str是用戶輸入字符串,len是要限制的位數
----------------------------
*/
function isSmall(str,len){
if (str.length<len){
return(true);
}else{
return(false);
}
}

/*判斷兩個字符串是否一致
---------------------------------
*/
function isSame(str1,str2){
if (str1==str2){
return(true);
}else{
return(false);
}
}


/*
判斷字符串是否爲空開始
---------------------------------
*/
function isNotNull(str){
if (str.length==""){
return(false);
}else{
return(true);
}
}
/*
判斷是不是手機號碼
---------------------------------
*/
function isPhone(str){

reg=/^[0]?13\d{9}$/gi;
reg2=/^[0]?15\d{9}$/gi;
if(!reg.test(str)&&!reg2.test(str)){
return false;
}
return true;
}
/*
判斷用戶名是否不包含漢字
(用戶名不能爲漢字,也不準帶有特殊字符)
注:
正則表達式.test() 方法用於檢測一個字符串是否匹配某個模式
---------------------------------
*/
function notChinese(str){
var reg=/[^A-Za-z0-9_]/g
if (reg.test(str)){
return (false);
}else{
return(true);
}
}


/*
判斷是否爲日期
----------------------------------
*/
function isDate (theStr) {
var the1st = theStr.indexOf('-');
var the2nd = theStr.lastIndexOf('-');

if (the1st == the2nd) {
return(false);
}
else {
var y = theStr.substring(0,the1st);
var m = theStr.substring(the1st+1,the2nd);
var d = theStr.substring(the2nd+1,theStr.length);
var maxDays = 31;

if (fucCheckNUM(m)==false || fucCheckNUM(d)==false || fucCheckNUM(y)==false) {
return(false); }
else if (y.length < 4) { return(false); }
else if ((m<1) || (m>12)) { return(false); }
else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
else if (m==2) {
if (y % 4 > 0) maxDays = 28;
else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
else maxDays = 29;
}
if ((m<1) || (m>maxDays)) { return(false); }
else { return(true); }
}
}
/*
判斷是否爲數字
---------------------------------------
*/
function isNum(num){
var i,j,strTemp;
strTemp="0123456789";
if ( num.length== 0){
return false;
}
for (i=0;i<num.length;i++){
j=strTemp.indexOf(num.charAt(i));
if (j==-1){//說明有字符不是數字
return false;
}
}

return true;//說明是數字
}


/*
判斷是否爲固定的位數

-------------------------
*/
function isAtn(str,n){
if (str.length!=n){
return(false);
}
else{
return(true);
}
}

/*
判斷是否爲電話號碼開始(已經完成)
--------------------------
*/
function isTel(telstr)
{
var reg1=/(\(\d{3}\)|\d{3}-)?\d{8}/g;//八位電話號碼
var reg2=/(\(\d{3}\)|\d{3}-)?\d{7}/g;//七位電話號碼
if (telstr!="") {
if (reg1.test(telstr)||reg2.test(telstr)){
return(true);
}
else{
return(false);
}
}else{return(false);}
}

/*
判斷是否爲email【最簡單的,驗證是否有@和.】(已經完成)
---------------------------
*/
function isEmail(emailstr) {
/*-------------------
if ((emailstr.indexOf('@', 0) == -1) || emailstr.indexOf('.') == -1) {
return false;
}
else {
return true;
}
---------------------*/
var reg=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i;
if (emailstr!="") {
if (reg.test(emailstr)){
return(true);
}
else{
return(false);
}
}
else{
return(false);
}
}
/*
判斷是否爲郵政編碼
---------------------------
*/
function isPostCode(str) {
var reg=/\d{6}/g;
if (str!="") {
if (reg.test(str)){
return(true);
}
else{
return(false);
}
}
else{
return(false);
}
}

/*
中文漢字輸入判斷
---------------------------
*/
function isChinese(str){
//如果值爲空,不通過校驗
if (str == "")
return false;
var pattern = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi;
if (pattern.test(str))
return true;
else
return false;
}
/*判斷用戶名是不是包含大小寫字母數字和_*/
function isUID(str){
var jgpattern =/^[A-Za-z0-9_]+$/;
var huzhaocard = str;
if(!jgpattern.test(huzhaocard))
{
return false;
}
else
{
return true;
}
}
//判斷是不是網址
function isHttp(str)
{
var pattern=/^(http:\/\/)?[a-zA-Z0-9-]+(\.[a-zA-z0-9-]+)+\/?$/gi;
if(pattern.test(str))
{

return true;
}
else
{
return false;
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章