我想验证在自动完成框中输入的特殊字符,例如 !@#$%^&*(),并可能会发出警告框消息“请输入有效名称”。下面是我的片段:
$("#txtName").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Webservice.asmx/GetNames",
data: "{'prefixText':'" + request.term + "'}",
dataType: "json",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('|')[0],
val: item.split('|')[1]
}
}))
},
error: function (result) {
ServiceFailed(result);
},
failure: function (response) {
ServiceFailed(result);
}
});
},
select: function (event, ui) {
autoName(ui.item.val, ui.item.label);
},
minLength: 4
}).data("autocomplete")._renderItem = function (ul, item) {
var newText = String(item.value).replace(
new RegExp(this.term, "gi"),
"<span class='ui-state-highlight'>$&</span>");
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + newText + "</a>")
.appendTo(ul);
}
任何帮助将非常感激。
提前致谢