比較常用的:
function checkIshanzi(s) {
//var patrn = /^[\u2E80-\u9FFF]$/; //Unicode編碼中的漢字范圍 /[^\x00-\x80]/
var patrn = /[^\x00-\x80]/;
if (!patrn.exec(s)) return false
return true
}
//校驗登錄名:只能輸入4-20個以字母開頭、可帶數字、“_”、“.”的字串
function checkIsRegisterUserName(s) {
var patrn = /^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){3,19}$/;
if (!patrn.exec(s)) return false
return true
}
//校驗用戶姓名:只能輸入4-30個以字母開頭的字串
function checkIsTrueName(s) {
var patrn = /^[a-zA-Z]{4,30}$/;
if (!patrn.exec(s)) return false
return true
}
//校驗密碼:只能輸入6-20個字母、數字、下划線
function checkIsPasswd(s) {
var patrn = /^(w){6,20}$/;
if (!patrn.exec(s)) return false
return true
}
//校驗普通電話、傳真號碼:可以“+”開頭,除數字外,可含有“-”
function checkIsTel(s) {
var patrn = /^[+]{0,1}(d){1,4}[ ]?([-]?((d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
//校驗手機號碼
function checkIsMobil(s) {
var patrn = /^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/;
if (!patrn.exec(s)) return false
return true
}
//校驗郵政編碼
function checkIsPostalCode(s) {
var patrn = /^[a-zA-Z0-9 ]{3,12}$/;
if (!patrn.exec(s)) return false
return true
}
//校驗是否IP地址
function checkIsIP(s) {
var patrn = /^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
//校驗EMail
function checkIsEMail(s) {
//var regex = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
//var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
var patrn = /^([0-9A-Za-z\-_\.]+)@([0-9A-Za-z]+\.[A-Za-z]{2,3}(\.[A-Za-z]{2})?)$/g;
if (!patrn.exec(s)) return false
return true
}
//驗證判斷類型
function check(axd,lbm,int) {
var s = $("#" + axd).val();
switch (int) {
case 0:
if (s == "") {
$("#textt").text(lbm + "不能為空");
$(".tip").fadeIn(200);
return false
}
break;
case 1:
if (!checkIsDigit(s)) {
$("#textt").text(lbm + "只能全由數字組成,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
case 2:
if (checkIsDigit(s)) {
$("#textt").text(lbm + "不能全由數字組成,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
case 3:
if (!checkIsRegisterUserName(s)) {
$("#textt").text(lbm + "只能輸入4-20個以字母開頭、可帶數字、“_”、“.”的字串,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
case 4:
if (!checkIsTrueName(s)) {
$("#textt").text(lbm + "只能輸入4-30個以字母開頭的字串,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
case 5:
if (!checkIsPasswd(s)) {
$("#textt").text(lbm + "只能輸入6-20個字母、數字、下划線,請重新輸入! ");
$(".tip").fadeIn(200);
return false
}
break;
case 6:
if (!checkIsTel(s)) {
$("#textt").text(lbm + "校驗普通電話、傳真號碼:可以“+”開頭,除數字外,可含有“-”,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
case 7:
if (!checkIsMobil(s)) {
$("#textt").text(lbm + "不正確,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
case 8:
if (!checkIsPostalCode(s)) {
$("#textt").text(lbm + "不正確,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
case 9:
if (!checkIsIP(s)) {
$("#textt").text(lbm + "不正確,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
case 10:
if (!checkIsEMail(s)) {
$("#textt").text(lbm + "不正確,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
case 11:
if (!checkIshanzi(s)) {
$("#textt").text(lbm + "只能全由漢字組成,請重新輸入!");
$(".tip").fadeIn(200);
return false
}
break;
}
return true
}
function checkrid(axd, lbm, int) {
var s = $("input[name=" + axd + "]:checked").val();
switch (int) {
case 0:
if (s == "") {
$("#textt").text(lbm + "不能為空");
$(".tip").fadeIn(200);
}
break;
}
}
//驗證判斷
function checked(asd) {
for (var i = 0; i < asd.length; i++) {
var axd = asd[i][0];
var lbm = asd[i][1];
var int = asd[i][2];
if (!check(axd, lbm, int)) {
return false;
break;
}
}
return true;
}
function ShowName(i) {
if (i == 1) {
$("#textt").text("修改成功");
$(".tip").fadeIn(200);
} else if (i == 0) {
$("#textt").text("添加成功");
$(".tip").fadeIn(200);
}if (i == 2) {
$("#textt").text("刪除成功");
$(".tip").fadeIn(200);
}
}
