阿贾克斯验证
我希望使用 OnBlur 事件(以覆盖按键以及剪切和粘贴事件)来使用 ajax 验证来验证表单元素。看起来jquery Validation 1.9确实有这个功能。任何人都可以确认它除了复制/粘贴条目之外还涵盖了键入的条目吗?有使用 Asp.net MVC2 的示例吗?我没有强类型视图,因此我的实现可能会比通常的示例稍微复杂一些...
到目前为止,我将尝试调用这个函数...
public string ValidateHosFin(string hospitalFin)
{
if (!true)
return "";
return "true";
}
这只是该函数真正用途的一个虚拟正在做...但这只是一个测试...到目前为止,我的 jquery 验证函数设置如下...
$("#temp1").validate({
rules: {
HospitalFinNumber: {
required: true,
minlength: 6,
remote: { url: '<%:Url.Action("ValidateHosFin", "PatientACO")%>', data: { hospitalFin: $('#HospitalFinNumber').val() }
}
}
}
我将验证的输入元素 id 是 HospitalFinNumber。 我如何确保这适用于按键输入事件以及复制粘贴事件?
I am looking to validate a form element using ajax validation using the OnBlur event (to cover key ups and cut and paste events). It looks like jquery Validation 1.9 does indeed have this feature. Can anyone confirm that it covers both key'ed entries in addition to copy/paste entries? Any examples of this using Asp.net MVC2? I do not have a strongly type view so my implementation may end being slightly more complicated that the usual example...
So far, I am going to try and call this function...
public string ValidateHosFin(string hospitalFin)
{
if (!true)
return "";
return "true";
}
This is just a dummy for what the function really will be doing... That is just a test however... So far, I have my jquery Validation function set up like so...
$("#temp1").validate({
rules: {
HospitalFinNumber: {
required: true,
minlength: 6,
remote: { url: '<%:Url.Action("ValidateHosFin", "PatientACO")%>', data: { hospitalFin: $('#HospitalFinNumber').val() }
}
}
}
The input element id for what I will be validating is HospitalFinNumber.
How can I ensure that this will work on both key input event's as well as copy paste events?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这将涵盖 onBlur 事件和复制/粘贴到字段中。另外,您可能想要修改服务器端验证操作,以便它返回 ActionResult 和 JSON:
另一个注释是您的远程验证规则。 值将是显示页面时文本框的值(可能是空的):
您应该让它返回一个函数,否则发送到服务器的 net/K87vL/9/" rel="nofollow">现场演示。
Yes, this will cover both onBlur events and copy/paste into the field. Also you might want to modify your server side validation action so that it returns an ActionResult and JSON:
Another remark is your remote validation rule. You should make it return a function or the value sent to the server will be the value that the textbox had at the moment the page was shown (which is probably empty):
And here's a live demo.