Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Funkcja sprawdzająca formularz, Sprawdzanie znaków w inpucie
di@blo
post
Post #1





Grupa: Zarejestrowani
Postów: 94
Pomógł: 0
Dołączył: 9.03.2005

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


Mam taki skrypt

  1. <script LANGUAGE="JavaScript">
  2. <!--
  3.  
  4. function check_form (form){
  5.  
  6. if (form.login.value == "")
  7. {
  8. alert("Nie podałe&para; Loginu");
  9. form.login.focus();
  10. return false;
  11. }
  12.  
  13. if (form.haslo.value == "")
  14. {
  15. alert("Nie podałe&para; hasła");
  16. form.haslo.focus();
  17. return false;
  18. }
  19.  
  20. if (form.login.value.length < "5")
  21. {
  22. alert("Login musi mieć przynajmniej 5 znaków");
  23. form.login.focus();
  24. return false;
  25. }
  26.  
  27. if (form.haslo.value < "5")
  28. {
  29. alert("Hasło musi mieć przynajmniej 5 znaków");
  30. form.haslo.focus();
  31. return false;
  32. }
  33.  
  34.  
  35. return true;
  36. }
  37. //-->
  38.  
  39. <form action="rejestracja.php3" method="post" onsubmit="return check_form(this);">
  40.  
  41. Login:<br>
  42. <input type="text" name="login" size="20" maxlength="20" class="wpisz"><br>
  43.  
  44. Hasło:<br>
  45. <input type="password" name="haslo" size="22" maxlength="20" class="wpisz">
  46.  
  47. <br><br>
  48. <input type="submit" value="Rejestruj">
  49. <input type="reset" value="Wyczy&para;ć">
  50.  
  51. </form>



Formularz jest przed wysłaniem i wszystko ok ale chciałbym zeby zamiast alertu obok inputa pojawił mi sie tekst w zależności jaki to był bład.

I drugie pytanie jak sprawdzić czy wpisany tekst do inputa zawiera inne znaki niż:
[B]a-z, A-Z, 0-9, '-', '_' ?

Z góry dzieki za pomoc
Go to the top of the page
+Quote Post
dasko
post
Post #2





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 9.11.2004

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


Robisz sobie spana jakiegoś np. o atrybucie 'id' rownym 'span'.
Kod
<script>
var span = document.getElementById('span');
span.innerText = 'takst ktory chcesz wysietlic';
</script>


A co do drugiego pytania to:
Kod
var exp = /^[^\w-]+$/;
if(exp.test(document.forms[0].jakiespole.value)) {
    alert('Wprowadzone przez ciebie dane muszą zawierać litery, cyfry, - lub _');
}
</script>

(IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
di@blo
post
Post #3





Grupa: Zarejestrowani
Postów: 94
Pomógł: 0
Dołączył: 9.03.2005

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


Zrobiłem sobie tak

<script>

if (form.login.value == "" || exp.test(form.login.value))
{ login.style.height = 'auto'}

</script>

i wstawiłem se diva

  1. <div id="login" style="align: center; color: red ; height: 1px; overflow: hidden;">BَD</div>


Ale jak schować tekst po ponownym submicie jeśli te pola bedą poprawne?

Dzieki za odpowiedzi

Ten post edytował di@blo 5.04.2005, 14:55:19
Go to the top of the page
+Quote Post
dasko
post
Post #4





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 9.11.2004

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


Kod
<script>
login.innerText = '';
</script>

(IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif) Albo w ogole usuwasz węzeł tekstowy:
Kod
<script>
login.removeChild(login.lastChild);

(IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 24.12.2025 - 19:28