you are here: codestackercodes [RSS] → tag scriptaculous [RSS]

realtime email validation

requires prototype and script.aculo.us
demo: http://ajaxorized.com/examples/scriptaculous/email.html

var isValid = false;

validateEmail = function(e) {
	if(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(e.value)) {
		if(!isValid) {
			$(e).morph('border-color:#00FF00', {duration:.3});
			isValid = true;
		}
	} else {
		if(isValid) {
			$(e).morph('border-color:#FF0000', {duration:.3});						
			isValid = false;					
		}
	}	
}

// <input type = "email" id = "myinput" onKeyUp = "validateEmail(this)" />
Displaying 1 Code