Simple Jquery Validation for Sending Multiple Email:
Use this submit button code, if your submit button with image,
$form['send'] = array(
'#type' => 'image_button',
'#src' => path_to_theme() . "/images/btn_0_0_send_off.gif",
'#attributes' => array('onclick' => "validateEmailForm(); return false;", 'onMouseOver'=>"this.src=Drupal.settings.basePath + 'your image path/btn_0_0_send_ro.gif';",'onMouseOut'=>"this.src=Drupal.settings.basePath + 'your image path/btn_0_0_send_off.gif';" ),
);
Now we are validating that Multiple email field,assume that the field id is"edit-mailid",..
$(function () {
validateEmailForm = function(){
var mailid = $('#edit-mailid').val();
/* Your Mail address Validation */
if(mailid == ''){
errorCount = 1;
error+="<li>You must supply a value for the 'mailid' field of this form.</li>";
}
else {
var result = mailid .split(",");
for(var i = 0;i < result.length;i++)
if(!validate_email(result[i])) {
errorCount = 1;
error+="<li>Please enter a valid email address</li>";
}
}
}
});
/**
* Function for validating Multiple email
*/
function validate_email(email)
{
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email))
{
return false;
}
else
{
return true;
}
}
No comments:
Post a Comment