When adding this tiny javascript to the onkeyup event of your inputbox,
the border will turn green when the email address. It uses scriptaculous' morph function to perform this transformation.
Realtime Email validation with Scriptaculous
When adding this tiny javascript to the onkeyup event of your
inputbox, the border will turn green when the email address. It uses scriptaculous' morph function to perform this transformation.
The inputbox (HTML):
-
- <input type = "email" id = "myinput" onKeyUp = "validateEmail(this)" />
-
The event handler (javascript):
-
- 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;
- }
- }
- }
-
|