ajax-prototype : validate email observer for input elements


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /* This is the email validator observer, it can passed events such as onblur,onkeypress,onclick*/
  2. function validateemail(event){
  3. var element = Event.findElement(event,'input');
  4. var str = element.value;
  5. var name = element.name;
  6. if((str.indexOf(".") > 2) && (str.indexOf("@") > 0)){
  7. $('emailerror'+name).innerHTML='';
  8. }
  9. else{
  10. new Effect.Highlight('emailaddress');
  11. if($('emailerror'+name)){
  12. $('emailerror'+name).innerHTML='*** Still Invalid Email! ***';
  13. }
  14. else{
  15. emailerror = new Insertion.After(element,'<div id="emailerror'+name+'">*** Invalid email! ***</div>');
  16. }
  17. }
  18. }
  19.  
  20. /* find all input elements where class = validateemail and apply validate observer*/
  21. $$('input.validateemail').each(function(element){
  22. Event.observe(element,'blur',validateemail,true);
  23. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.