Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Czy istnieje funkcja sprawdzajaca czy ciag znakow jest alphanumeric
macpain1982
post 8.02.2012, 18:47:33
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 8.02.2012

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


Witam,
Podobnie jak w temacie. Znalazlem funckje ctype_alnum ale ona zwraca true nawet gdy ciag znakow jest tylko np. liczbami.
Czy istnieje w php funckja sprawdzajaca czy w ciagu znakow istnieja i liczby i litery nie chodzi mi o wyrazenia regularne.

Pozdrawiam
Go to the top of the page
+Quote Post
Turson
post 8.02.2012, 19:59:56
Post #2





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


  1. if(preg_match("/^\w+$/",$zmienna)){
  2. //zawiera tylko litery i cyfry
  3. }
  4. else
  5. {
  6. //nie zawiera
  7. }


Ten post edytował TursoN 8.02.2012, 20:00:54
Go to the top of the page
+Quote Post
macpain1982
post 10.02.2012, 12:42:28
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 8.02.2012

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


Cytat(TursoN @ 8.02.2012, 19:59:56 ) *
  1. if(preg_match("/^\w+$/",$zmienna)){
  2. //zawiera tylko litery i cyfry
  3. }
  4. else
  5. {
  6. //nie zawiera
  7. }


Podajac zmienna:
Kod
$zmienna = '12345678';

Twoj kod zwraca "zawiera tylko litery i cyfry", a mi chodzito o to, ze string powinin zawirac i liczby i litery.
Go to the top of the page
+Quote Post
Morfi777
post 10.02.2012, 13:01:37
Post #4





Grupa: Zarejestrowani
Postów: 76
Pomógł: 1
Dołączył: 5.09.2007

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


Hej.

  1. <?
  2.  
  3. $letters = 'asd';
  4. $numbers = '123';
  5. $lettnum = 'asd123';
  6. $lettnum2 = 'asd123asd';
  7. $lettnum3 = '123asd';
  8. $lettnum4 = '123a11sd';
  9.  
  10. if( preg_match('/(?=.*[A-Za-z])(?=.*[0-9])/', $letters ) )
  11. print 'ok:';
  12. else
  13. print 'not:';
  14.  
  15. if( preg_match('/(?=.*[A-Za-z])(?=.*[0-9])/', $numbers ) )
  16. print 'ok:';
  17. else
  18. print 'not:';
  19.  
  20. if( preg_match('/(?=.*[A-Za-z])(?=.*[0-9])/', $lettnum ) )
  21. print 'ok:';
  22. else
  23. print 'not:';
  24.  
  25. if( preg_match('/(?=.*[A-Za-z])(?=.*[0-9])/', $lettnum2 ) )
  26. print 'ok:';
  27. else
  28. print 'not:';
  29.  
  30. if( preg_match('/(?=.*[A-Za-z])(?=.*[0-9])/', $lettnum3 ) )
  31. print 'ok:';
  32. else
  33. print 'not:';
  34.  
  35. if( preg_match('/(?=.*[A-Za-z])(?=.*[0-9])/', $lettnum4 ) )
  36. print 'ok:';
  37. else
  38. print 'not:';
  39.  
  40.  
  41. ?>


E: http://ideone.com/rywnh

Ten post edytował Morfi777 10.02.2012, 13:05:33
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: 20.06.2025 - 08:56