jquery使用者登入驗證,是否有特殊字元
$.extend($.fn.validatebox.defaults.rules, {
loginName: {
validator: function (value, param) {
return /^[\u0391-\uFFE5\w]+$/.test(value);
},
message: '只允許漢字、英文字母、數字及下劃線。'
}
});
//使用者名稱寫入"請輸入管理員使用者名稱!"js
$("#txtName").val("請輸入管理員使用者名稱!");
//使用者名稱寫入"請輸入管理員使用者名稱!"js
//使用者名稱輸入js
//當文字框等到焦點
$("#txtName").focus(function () {
if ($("#txtName").val() == "請輸入管理員使用者名稱!") {
$("#txtName").val("");
}
});
//當文字框失去焦點
$("#txtName").blur(function () {
var checking = false;
var txtName = $("#txtName").val();
//當文字框為空
if (txtName == "") {
$("#txtName").val("請輸入管理員使用者名稱!");
$("#prompt_txtName").text("請輸入管理員使用者名稱!");
$("#prompt_txtName").text("使用者名稱不能為空!");
}
//當文字框沒有變化
else if (txtName == "請輸入管理員使用者名稱!") {
$("#prompt_txtName").text("請按要求填寫使用者名稱!");
}
//只允許漢字、英文字母、數字、下劃線!
else if (!txtName.match(/^[\u4E00-\u9FA5a-zA-Z0-9_]{0,}$/)) {//.match(/^[\u4E00-\u9FA5a-zA-Z0-9_]{3,20}$/) //{3,20}$表示是長度3-20
$("#prompt_txtName").text("只允許漢字、英文字母、數字、下劃線!");
}
//郵箱驗證
else if (!txtName.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
$("#prompt_txtName").text("請輸入正確的郵箱格式!");
}
//文字框的內容的長度
else if (txtName.length > 20 || txtName.length < 3) {
$("#prompt_txtName").text("長度在3-20之間!");
}