Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript] formularz - input mail
Forum PHP.pl > Forum > Przedszkole
tenloginjestzajety
Witam mam formularz, który działa prawidłowo chciałbym jednak zrobić warunek, że w polu input musi być wpisany znak: @. Dzięki

  1. <script type="text/javascript">
  2. function hide(x){x.value=''}
  3. </script>
  4. <script type="text/javascript">
  5. function error(tekst) {
  6. if (errfound) return;
  7. errfound = true;}
  8. function validate(id) {
  9. errfound = false;
  10. var errors = "";
  11. if (document.getElementById('description').value == ""){errors += "description is empty. \n";document.getElementById('description').style.backgroundColor = "#FFDFDF";}
  12. else {document.getElementById('description').style.backgroundColor = "#b9fdbb";}
  13. if (document.getElementById('mail').value == ""){errors += "description is empty. \n";document.getElementById('mail').style.backgroundColor = "#FFDFDF";}
  14. else {document.getElementById('mail').style.backgroundColor = "#b9fdbb";}
  15. if (errors != "") error(errors); return !errfound;}
  16. </script>
  17. <input type="text" class="textinput" name="mail" id="mail" onfocus="hide(this)" value="Twój e-mail" />


W PHP sprawdzenie robię tak:
  1. <?php
  2. $tekst = 'jakiś tekst zawierający.';
  3. if(strpos($tekst, '@')!==false) {echo 'zawiera';} else {echo 'nie zawiera';}
  4. ?>
Comandeer
A nie lepiej wykorzystać natywną walidację w HTML5 (input[type=email]) i natywną walidację maili w PHP (filter_var)?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.