JQuery single element validation not respecting rules -


i cannot crack 1 - have simple form textbox , button (not submit). want users enter email address , when press button, added list of addresses displayed on page. need validate user entry see if valid email address.

html:

<form id="invitefriendsform">      email address: <input type="text" id="cemail" name="someemail" value="" />      <input type="button" id="addemail" value="add email" />   </form> 

jquery:

$("#addemail").click(function() {     var isvalid = $("#invitefriendsform").validate({        rules: { cemail: { required: true, email: true } }     } ).element("#cemail");      if(isvalid) {         alert($("#cemail").val());     }     else {         alert('wrong email');     } }); 

the problem have isvalid variable true. please note alerts there not because use indicate error user, code wise need know whether should continue processing user input or not.

just record, i'm using jquery validation plugin 1.8.0

thanks lot,

antonin

  1. make button submit button.
  2. use validate's submithandler property change happens when form validates.
  3. let validate's error display thing. if need alert instead of error label, can change how error displays (check documentation).

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -