Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> walidacja formularza nt-y raz, Puste pole nie są jednak zawsze puste :(
DrJOB
post 17.08.2006, 14:00:27
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 8.02.2006

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


Witam,

sprawdzenie czy pole jest pouste poprzez:
Kod
if(pole == "" || pole == null){...}

nie działa jeśli w pole klepniemy spacje.
Co wtedy?

Pozdrawiam
Go to the top of the page
+Quote Post
gekon
post 17.08.2006, 14:48:08
Post #2





Grupa: Zarejestrowani
Postów: 614
Pomógł: 7
Dołączył: 10.11.2003
Skąd: Rzeszów/Kraków

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


  1. function trim(TheString)
  2. {
  3. var len;
  4.  
  5. len = TheString.length;
  6. while(TheString.substring(0,1) == " "){ //trim left
  7. TheString = TheString.substring(1, len);
  8. len = TheString.length;
  9. }
  10.  
  11. while(TheString.substring(len-1, len) == " "){ //trim right
  12. TheString = TheString.substring(0, len-1);
  13. len = TheString.length;
  14. }
  15. return TheString;
  16. }

  1. if(trim(pole) == "" || pole == null){...}


--------------------
Pokaż kod = Pokaż CAŁY kod, najlepiej działający na jakimś serwerze.
Fanatycy | glazar.info | semantyka | HTML i XHTML FAQ
Go to the top of the page
+Quote Post
dyktek
post 17.08.2006, 14:49:36
Post #3





Grupa: Zarejestrowani
Postów: 240
Pomógł: 0
Dołączył: 18.01.2004
Skąd: rzeszów / kraków

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


wtedy smile.gif
  1. tresc = //tresc z twojego pola
  2.  
  3. regExp = /^(.*{1,})$/;
  4.  
  5. if( regExp.test(tresc) ){
  6. //jest jakis znak
  7. }


powinno działać

Ten post edytował dyktek 17.08.2006, 14:52:16
Go to the top of the page
+Quote Post
DrJOB
post 17.08.2006, 14:53:29
Post #4





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 8.02.2006

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


Super biggrin.gif

znalazlem jeszcze cos takiego
Kod
    function isblank(s){
        for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
    }


Pozdrawiam i dzieki
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: 21.06.2025 - 12:04