[jQuery] [validate] Re: [validate] validate: response from remote rule
Weird, the 'validate' didn't show in my subject, maybe it will now. Well, I figured out a solution, and it works pretty well :D var email_ajax_data; $.validator.addClassRules({ email: { required: true, email: true, remote: { url: /ajax/check_email, type: post, dataFilter: function(data) { email_ajax_data = data; return data; }, complete: function() { status = eval( '('+email_ajax_data+')' ); if (status == 'false' || !status) { //if false show msg $('#email_notice').show(); } else { $('#email_notice').hide(); } } } } }); In this example I don't use it for much, but I'm also using it in a number of other sections where it supplies a larger json response. I could use a json parser, but I trust my site, lol. The dataFilter and complete complete callbacks were unused by the validation plugin, so free to use. Since complete is called no matter what, you need to manually check for success, since it succeeds as long as the response exists and doesn't equal false, that's not to hard. The dataFilter is called before jQuery parses the response, so you need to parse it yourself, however you need to. But this solution expands the form plug-in functionality by lots. At least if the response is successful. Since it specifically checks if the response is false on fail, you can't send anything else but that. -Adam On Apr 8, 9:13 pm, phazei pha...@gmail.com wrote: Jörn, or anyone else familiar with the jQuery validator and ajax I am making a form that asks for the persons address, but when they type in the zip code, I need to both check it from in a db and make sure it's listed, and if it is, return the city and state. I figured out the validator needs the ajax to specifically return the text 'false' to be invalid, and anything else evaluates to valid. But I need to take the response data and do stuff with it. I tried using: remote: { success: function(){ ... } } But it overwrites the default one. I tried copying all the data from the default into mine, but nothing happened then. I was able to .bind ajaxSuccess to the body, but if I alert (response.toSource()), it shows data:(void 0) no matter what and undefined if I alert(response.data). I can use: remote: { complete: function(){ ... } } But it doesn't have the data How can I get the data back to play with without modding the validate class? I can use the complete call back if I can get the data. If I do need to mod it, I was just going to throw it into a global var at the beginning of the success call. Help, Adam
[jQuery] Re: comma-seperated multiple emails validation
You can use the custom methods. View source on this example: http://jquery.bassistance.de/validate/demo/custom-methods-demo.html jQuery.validator.addMethod(email_multiple, function(value, element, param) { return this.optional(element) || /^[((([a-z]|\d|[!#\$%'\*\+\-\/=\? \^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\ $%'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+) *)|((\x22)\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c \x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF \uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900- \uFDCF\uFDF0-\uFFEF]*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)? (\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a- z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~| [\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF \uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF \uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a- z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]| [\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?([;]?|[,]?)]+$/i.test (value); }, jQuery.validator.messages.email); I think I modded it right, it's untested. I went: [regex([,]?|[;]?)[ ]?]+ (seperated by a optional ',' or ';' followed by an optional space) On Apr 8, 5:39 pm, Buntu J buntu.w...@gmail.com wrote: Hi, Is there a way to reuse the email method in the Validate plugin on the input field which takes multiple email addresses separated by comma? Thanks for the help!
[jQuery] [validate] response from remote rule
Jörn, or anyone else familiar with the jQuery validator and ajax I am making a form that asks for the persons address, but when they type in the zip code, I need to both check it from in a db and make sure it's listed, and if it is, return the city and state. I figured out the validator needs the ajax to specifically return the text 'false' to be invalid, and anything else evaluates to valid. But I need to take the response data and do stuff with it. I tried using: remote: { success: function(){ ... } } But it overwrites the default one. I tried copying all the data from the default into mine, but nothing happened then. I was able to .bind ajaxSuccess to the body, but if I alert (response.toSource()), it shows data:(void 0) no matter what and undefined if I alert(response.data). I can use: remote: { complete: function(){ ... } } But it doesn't have the data How can I get the data back to play with without modding the validate class? I can use the complete call back if I can get the data. If I do need to mod it, I was just going to throw it into a global var at the beginning of the success call. Help, Adam