Posted By

sircambridge on 10/03/06


Tagged


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

Hollow
vali29
hans
nreliu
umang_nine


ajax-prototype : validate email observer for input elements


 / Published in: Other
 

  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
Posted By: sircambridge on October 3, 2006

to use : for an input element, set it as

You need to login to post a comment.