jQuery UI Widgets Forums Plugins Validator, Drag & Drop, Sortable Multiple rules on same field

This topic contains 2 replies, has 2 voices, and was last updated by  infrase 8 years, 10 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Multiple rules on same field #78378

    infrase
    Participant

    Hallo,
    I want to validate an email address field with my custom function but only when the built in validation rules ‘required’ and ’email’ are passed. My function verify if the email really exist and it need a bit of time to execute and it costs. Is there a way to catch the validation result of a build in rules like ’email’?
    My code is:

    jQuery('#pps_data').jqxValidator({
    	hintType : 'label',
      	rules: [
      		{ input: '#mail', message: 'Email is required!', action: 'blur', rule: 'required' },
      		{ input: '#mail', message: 'Email not valid!', action: 'blur', rule: 'email' },
      		{ input: '#mail', message: 'This email does not exist!', action: 'blur', rule: function (input, commit) {
      			var mailToChk = jQuery('#mail').val().trim() ;
      			jQuery.ajax({
      				url: "my-verify.php",
      				type: 'POST',
      				data: { mail: jQuery('#mail').val().trim(), 
    	  				name_surname: jQuery('#name_surname').val()
    	  				},
    				success: function(data)
    					{
    						if (data == "true")
    							{
    							commit(true);
    							}
    						else commit(false);
    					},			
    				error: function()
    					{
    						commit(false);
    					}
    			});
    		}
    		},
    	]
    });
    

    Thanks for any suggestion,
    Nicoletta

    Multiple rules on same field #78386

    Dimitar
    Participant

    Hello Nicoletta,

    You can apply multiple rules (as you have already done), but they are independent. If you wish, you can check for “required” and “email” all in your custom rule. The following Stack Overflow topic shows how to validate an email in JavaScript: http://stackoverflow.com/questions/46155/validate-email-address-in-javascript.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Multiple rules on same field #78392

    infrase
    Participant

    Ok, thanks!

    Nicoletta

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.