Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript] formularz - input mail
tenloginjestzaje...
post 17.10.2016, 20:36:22
Post #1





Grupa: Zarejestrowani
Postów: 358
Pomógł: 1
Dołączył: 20.07.2014

Ostrzeżenie: (0%)
-----


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. ?>


Ten post edytował tenloginjestzajety 17.10.2016, 20:43:46


--------------------
Nigdy nie zapominam kliknąć "pomógł". Zastosowanie na stronie [prosze nie spamuj]
Go to the top of the page
+Quote Post
Comandeer
post 17.10.2016, 22:10:20
Post #2





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

Ostrzeżenie: (0%)
-----


A nie lepiej wykorzystać natywną walidację w HTML5 (input[type=email]) i natywną walidację maili w PHP (filter_var)?


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 27.04.2024 - 03:09