Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805

    ferifica campi d input ma non effettua il controllo dell email

    salve ragazzi , ho trovato uno script che se il campo d input e vuoto,fa diventare lo sfondo del campo in un determinato colore, adesso ragazzi come potrei fare a questo script ad aggiungre anche il controllo email? lo script e questo :
    codice:
    
    <script language="Javascript" type="text/javascript">
    function ValidateThenPost() {
      var FN = document.getElementById('email');
      var CA = document.getElementById('commentarea');
      var CP = document.getElementById('nome');
      
      if (CP != undefined)
      {
        if (CP.value == '') { CP.style.backgroundColor = '#ffcccc'; return; } else { CP.style.backgroundColor = '#ffffff'; }
      }
      
      if (FN != undefined)
        if (FN.value == '') { FN.style.backgroundColor = '#ffcccc'; return; } else { FN.style.backgroundColor = '#ffffff'; }
      if (CA.value == '') { CA.style.backgroundColor = '#ffcccc'; return; } else { CA.style.backgroundColor = '#ffffff'; }
      document.getElementById('commentform').submit();
    }
    </script>
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    puoi usare questa Reg Expr:

    var testMail = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

    Presa da http://xyfer.blogspot.com/2005/01/ja...validator.html

    poi ti basta

    var FN = document.getElementById('email');

    ...

    if (FN.value == '' || !testMail.test(FN.value)){...

    Questo controlla se il value del campo mail è vuoto o non passa il test per l'indirizzo e-mail contenuto nella regexpr.
    I DON'T Double Click!

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    ciao cortesemente mi faresti vedere come fare non conosco il javascript grazie
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  4. #4
    codice:
    <script language="Javascript" type="text/javascript">
    function ValidateThenPost() {
      var testMail = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
    
      var FN = document.getElementById('email');
      var CA = document.getElementById('commentarea');
      var CP = document.getElementById('nome');
      
      if (CP != undefined)
      {
        if (CP.value == '') { CP.style.backgroundColor = '#ffcccc'; return; } else { CP.style.backgroundColor = '#ffffff'; }
      }
      
      if (FN != undefined)
        if (FN.value == '' || !testMail.test(FN.value)) { FN.style.backgroundColor = '#ffcccc'; return; } else { FN.style.backgroundColor = '#ffffff'; }
      if (CA.value == '') { CA.style.backgroundColor = '#ffcccc'; return; } else { CA.style.backgroundColor = '#ffffff'; }
      document.getElementById('commentform').submit();
    }
    </script>
    I DON'T Double Click!

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,805
    grazie infinite a buon rendere
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.