Return to Snippet

Revision: 1412
at October 3, 2006 15:37 by sircambridge


Initial Code
/* This is the email validator observer, it can passed events such as onblur,onkeypress,onclick*/
function validateemail(event){
	var element = Event.findElement(event,'input');
	var str = element.value;
	var name = element.name;	
	if((str.indexOf(".") > 2) && (str.indexOf("@") > 0)){
		$('emailerror'+name).innerHTML='';
	} 
	else{
		new Effect.Highlight('emailaddress');
		if($('emailerror'+name)){
			$('emailerror'+name).innerHTML='*** Still Invalid Email! ***';
		}
		else{
			emailerror = new Insertion.After(element,'<div id="emailerror'+name+'">*** Invalid email! ***</div>');
		}
	}
}

/* find all input elements where class = validateemail and apply validate observer*/
$$('input.validateemail').each(function(element){
	Event.observe(element,'blur',validateemail,true);
});

Initial URL

                                

Initial Description

                                

Initial Title
ajax-prototype : validate email observer for input elements

Initial Tags

                                

Initial Language
Other