我正在使用JörnZaefferer的JQuery驗證,但我需要進行一些數據庫調用來驗證某些字段(例如檢查用戶名是否唯一)。這是可能使用這個插件,如果是這樣,有人有一些語法的例子嗎?這裏是我當前的代碼:JQuery驗證和數據庫調用
$("form").validate({
rules: {
txtUserName: {
required: true,
minlength: 4
},
txtPassword: {
required: true
},
txtConfirmPassword: {
required: true,
equalTo: "#txtPassword"
},
txtEmailAddress: {
required: true,
email: true
},
txtTelephoneNumber: {
required: true,
number: true
}
},
messages: {
txtUserName: {
required: "Please enter a User Name",
minlength: "User Name must be at least 4 characters"
},
txtPassword: {
required: "Please enter a Password"
},
txtConfirmPassword: {
required: "Please confirm Password",
equalTo: "Confirm Password must match Password"
},
txtEmailAddress: {
required: "Please enter an Email Address",
email: "Please enter a valid Email Address"
},
txtTelephoneNumber: {
required: "Please enter a Telephone Number",
number: "Telephone Number must be numeric"
}
}
});
});
編輯:
我已經走到這一步,但我這樣做的時候,我失去了我的窗體上的值,大概是因爲格式已經張貼在這裏?
$("form").validate({
//errorLabelContainer: $("#divErrors"),
rules: {
txtUserName: {
required: true,
minlength: 4
},
txtPassword: {
required: true
},
txtConfirmPassword: {
required: true,
equalTo: "#txtPassword"
},
txtEmailAddress: {
required: true,
email: true
},
txtTelephoneNumber: {
required: true,
number: true//,
//postalCode:true
}
},
messages: {
txtUserName: {
required: "Please enter a User Name",
minlength: "User Name must be at least 4 characters"
},
txtPassword: {
required: "Please enter a Password"
},
txtConfirmPassword: {
required: "Please confirm Password",
equalTo: "Confirm Password must match Password"
},
txtEmailAddress: {
required: "Please enter an Email Address",
email: "Please enter a valid Email Address"
},
txtTelephoneNumber: {
required: "Please enter a Telephone Number",
number: "Telephone Number must be numeric"
}
},
onValid: addUser()
});
});
功能ADDUSER(){
alert($('input[name="txtUserName"]').val());
}
檢查尼克的回答是> http://stackoverflow.com/questions/3650909/jquery-validate/3650937#3650937 – neebz 2011-04-04 09:59:14
看着這個線程後,我想這一點,但我的web服務似乎並不被稱爲: – user517406 2011-04-04 10:14:23
能你添加你的代碼?客戶端和服務器端 – neebz 2011-04-04 10:15:30