在函数上设置jquery验证标签(set jquery validation label on function)

编程入门 行业动态 更新时间:2024-10-21 19:28:57
函数上设置jquery验证标签(set jquery validation label on function)

早上,我想在函数onkeyup返回false时调用标签,例如。 我设置了jquery验证器,并设置了一个规则

e-mail: { email:true, required:true }

但我有另一个函数验证电子邮件,如果不正确则返回false,如果相反则返回true。

function emailvalidate(email_string){ [regex test emailstring] return true or false //(and show label of jqueryvalidator) }

现在,当我写一个无效的电子邮件时,Jquery验证器显示一个标签说email wrong但我还需要在keyup或焦点其他字段上它将使用我的函数emailvalidate()测试电子邮件表单值,如果它返回false,它将显示jquery验证器插件的消息。 某事

$("#email-field").on("keyup",emailvalidate($("#email-field").val()))

Morning, I wanna call the label when a function onkeyup return false, for example. I set jquery validator, and i set a rule clled

e-mail: { email:true, required:true }

but I have another function that validate the email and return false if it is not correct and true if the opposite.

function emailvalidate(email_string){ [regex test emailstring] return true or false //(and show label of jqueryvalidator) }

now, when I write an invalid email Jquery validator shows a label saying email wrong but I need also that on keyup or on focus other field it will test the email form value with my function emailvalidate() and if it returns false it will show the message of the jquery validator plugin. sth like

$("#email-field").on("keyup",emailvalidate($("#email-field").val()))

最满意答案

好吧,如果你能使用这个js验证码来验证,我对你的插件一无所知

function ValidateEmail(mail) { if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true) } return (false) } $(document).ready(function() { $("#email-field").on("keyup",function(e){ var mail = $("#email-field").val(); var result = ValidateEmail(mail); if(result == true){ //do something here }else{ //do something here } return result; e.preventDefault(); }); });

well i dont have any idea about your plugin well if you will you can use this js validation code to validate

function ValidateEmail(mail) { if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true) } return (false) } $(document).ready(function() { $("#email-field").on("keyup",function(e){ var mail = $("#email-field").val(); var result = ValidateEmail(mail); if(result == true){ //do something here }else{ //do something here } return result; e.preventDefault(); }); });

更多推荐

本文发布于:2023-07-16 07:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1125474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   标签   jquery   set   label

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!