This is a translated page. The original can be found here: http://iwebdevel.com/2009/06/13/javascript-how-to-validate-email-address-with-javascript/
UPDATES VIA RSS | Email Aggiornamenti via RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / JavaScript & Ajax / Javascript: How to validate … Home / Coding / JavaScript e Ajax / Javascript: Come convalidare ...

Javascript: How to validate email address with JavaScript? Javascript: Come validare indirizzo email con JavaScript?

Posted on 13. Pubblicato il 13. Jun, 2009 by Dragos in Coding , JavaScript & Ajax Giugno, 2009 da Dragos in Coding, JavaScript e Ajax

Here's a piece of code I found while I was browsing the JQuery UI pages to easily validate email addresses. Ecco un pezzo di codice ho trovato mentre stavo navigando le pagine jQuery UI facilmente convalidare gli indirizzi e-mail.

The code below represents a general validation function, that requires two parameters:1. Il codice qui sotto rappresenta una funzione generale di convalida, che richiede due parametri: 1. the string value of an obkect and 2. il valore stringa di un obkect e 2. the regular expression to check the string against l'espressione regolare per verificare la stringa contro

 function checkRegexp(o,regexp) { funzione checkRegexp (o, regexp) ( 
         if ( !( regexp.test( o ) ) ) { if (! (regexp.test (o))) ( 
             return false; return false; 
         } else { Else () 
             return true; return true; 
         } ) 
     } ) 

Now, here's the following code to use in order to validate email addresses: Ora, ecco il codice riportato di seguito per utilizzare al fine di convalidare gli indirizzi e-mail:

 var regex=/^((([az]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([az]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([az]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([az]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([az]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([az]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([az]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([az]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([az]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([az]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i; var regex =/^((([ AZ] | \ d | [! # \ $% & '\ * \ + \ - \ / = \? \ ^ _ `(\ |}~]|[ \ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF]) + (\. ([AZ] | \ d | [! # \ $% & '\ * \ + \ - \ / = \? \ ^ _ `(\ |}~]|[ \ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF ])+)*)|(( \ x22 )(((( \ x20 | \ x09) * (\ x0d \ x0a) )? (\ x20 | \ x09 )+)?(([ \ x01-\ x08 \ x0b \ x0c \ x0E-\ x1f \ x7f] | \ x21 | [\ x23-\ x5b] | [\ 5d-\ x7e ] | [\ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF]) | (\ \ ([\ x01-\ x09 \ x0b \ x0c \ x0d-\ x7f] | [\ u00A0-\ uD7FF \ uF900 - \ uFDCF \ uFDF0-\ uFFEF ]))))*((( \ x20 | \ x09) * (\ x0d \ x0a))? (\ x20 | \ x09 )+)?( \ x22 )))@( (([az] | \ d | [\ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF ])|(([ AZ] | \ d | [\ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0 - \ uFFEF]) ([az] | \ d | - | \ .|_|~|[ \ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF ])*([ AZ] | \ d | [ \ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF]))) \ .)+(([ az] | [\ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF ])|(( [az] | [\ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF]) ([az] | \ d | - | \ .|_|~|[ \ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF ])*([ az] | [\ u00A0-\ uD7FF \ uF900-\ uFDCF \ uFDF0-\ uFFEF]))) \.? $ / i; 
 var first=checkRegexp("email@email.",regex); //boolean false, because the email address is missing the tld var prima = checkRegexp ( "email @ email." regex); / / boolean false, perché l'indirizzo e-mail manca il TLD 
 var second=checkRegexp("email@email.tld",regex); //boolean true var secondi = checkRegexp ( "email@email.tld", regex); / / boolean true 

It's good to validate email addresses right on the client side, because you save server resources consumption and the client is also able to correct any errors faster, without reloading the page. E 'bello per convalidare gli indirizzi e-mail a destra sul lato client, in quanto si salva il consumo di risorse del server e il client è in grado di correggere eventuali errori più veloce, senza ricaricare la pagina. But you should never avoid rechecking the email (and not only emails) on the server side. Ma non si dovrebbe mai evitare di ricontrollare la posta elettronica (e-mail non solo) sul lato server.

Translate this post Traduci questo post


Related posts: Related posts:

  1. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Invia funzione come parametro a un'altra funzione (callback)
  2. PHP: Script to extract one's contacts from email (Gmail, Yahoo,Hotmail,AOL…) and send invites – OpenInviter to go! PHP: script per estrarre i propri contatti di posta elettronica (Gmail, Yahoo, Hotmail, AOL ...) ed inviare invita - OpenInviter to go!
  3. JavaScript: Get anchor from URL JavaScript: Get ancora da URL
  4. JavaScript: GIFless animation. JavaScript: animazione GIFless. Animate images,logos with jQuery Animare le immagini, i loghi con jQuery
  5. JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Come ottenere l'indice (posizione all'interno di un gruppo) di un oggetto con jQuery?

    blog comments powered by Disqus commenti del blog powered by Disqus