Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> wyrażenia regularne
matt
post 24.07.2004, 11:05:09
Post #1





Grupa: Zarejestrowani
Postów: 82
Pomógł: 0
Dołączył: 12.08.2003
Skąd: Kalisz

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


oo aaa

od rana meczy mnie jeden problem, a dokładniej format pewnych danych.

chce zeby przy dodawaniu sezony do bazyy danych wymagany format byl LLLL/LLLL np 2004/2005 no i nie moge nic wykombinowac sadsmiley02.gif
takie cos mam

  1. <?php
  2. else if (ereg(&#092;"[1-9]+./+[1-9]\",$sezon)) {
  3.  $blad++;
  4.  echo &#092;"<center><b>Komunikat:</b>&nbsp; Zły format danych. Format pola <b>Sezon</b> musi być 0000/0000.<br></center>\";
  5. } 
  6. ?>


prosilbym tez o jakis dobry art lub cos na temat wyrażen regularnych :roll2:
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
netzah
post 24.07.2004, 11:10:33
Post #2





Grupa: Zarejestrowani
Postów: 109
Pomógł: 1
Dołączył: 19.03.2004

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


Np. to sie nada:
LLLL/LLLL -> [0-9]{4}/[0-9]{4}
Go to the top of the page
+Quote Post
matt
post 24.07.2004, 11:18:10
Post #3





Grupa: Zarejestrowani
Postów: 82
Pomógł: 0
Dołączył: 12.08.2003
Skąd: Kalisz

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


Cytat(netzah @ 2004-07-24 12:10:33)
Np. to sie nada:
LLLL/LLLL -> [0-9]{4}/[0-9]{4}

nie pomogło sadsmiley02.gif

zapodaje jeszcze cały kod ktory sprawdza dane z formularza
  1. <?php
  2. $sezon = trim($_POST[&#092;"sezon\"]);
  3.  
  4. if (strlen($sezon)==0) {
  5. $blad++;
  6. echo &#092;"<center><b>Komunikat:</b>&nbsp; Pole <b>Sezon</b> nie może być puste.<br></center>\";
  7. }  else if (ereg(&#092;"[a-zA-Z+_-]\",$sezon)) {
  8. $blad++;
  9. echo &#092;"<center><b>Komunikat:</b>&nbsp; Pole <b>Sezon</b> nie może zawierać liter.<br></center>\";
  10. }
  11.  else if (ereg(&#092;"[0-9]{4}/[0-9]{4}\",$sezon)) {
  12. $blad++;
  13. echo &#092;"<center><b>Komunikat:</b>&nbsp; Zły format danych. Format pola <b>Sezon</b> musi być 0000/0000.<br></
  14.  
  15. center>&#092;";
  16. }
  17.  
  18.  
  19. if ($blad==0) {...
  20. ?>
Go to the top of the page
+Quote Post
Dabroz
post 24.07.2004, 11:30:30
Post #4





Grupa: Zarejestrowani
Postów: 286
Pomógł: 0
Dołączył: 1.11.2003
Skąd: Poland, Płock

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


  1. <?php
  2.  
  3. $sezon=trim($_POST['sezon']);
  4.  
  5. if (!preg_match('#^d{4}/d{4}$#',$sezon))
  6. {
  7. echo(&#092;"<p>Zły format danych. Format pola <b>Sezon</b> musi być 0000/0000.</p>\");
  8. }
  9.  
  10. ?>


--------------------
Go to the top of the page
+Quote Post
matt
post 24.07.2004, 11:35:07
Post #5





Grupa: Zarejestrowani
Postów: 82
Pomógł: 0
Dołączył: 12.08.2003
Skąd: Kalisz

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


moze to glupie ale nadal zle sad.gif

jak zrobie 2004-2005 to dodaje :/

a chce zeby tylko moglo przejsc z LLLL/LLLL np 2004/2005 :/
Go to the top of the page
+Quote Post
Dabroz
post 24.07.2004, 11:46:21
Post #6





Grupa: Zarejestrowani
Postów: 286
Pomógł: 0
Dołączył: 1.11.2003
Skąd: Poland, Płock

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


U mnie dodaje tylko jeżeli użyjesz 0000/0000.
Zamieniłeś krzaki na ! ?


--------------------
Go to the top of the page
+Quote Post
matt
post 24.07.2004, 11:49:06
Post #7





Grupa: Zarejestrowani
Postów: 82
Pomógł: 0
Dołączył: 12.08.2003
Skąd: Kalisz

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


teraz to nic w ogole nie działa, tzn nie chce dodawac laugh.gif

jest tak:

  1. <?php
  2. $sezon = trim($_POST[&#092;"sezon\"]);
  3.  
  4. if (strlen($sezon)==0) {
  5. $blad++;
  6. echo &#092;"<center><b>Komunikat:</b>&nbsp; Pole <b>Sezon</b> nie może być puste.<br></center>\";
  7. }  else if (ereg(&#092;"[a-zA-Z]\",$sezon)) {
  8. $blad++;
  9. echo &#092;"<center><b>Komunikat:</b>&nbsp; Pole <b>Sezon</b> nie może zawierać liter.<br></center>\";
  10. }
  11.  else if (preg_match('#^d{4}/d{4}$#',$sezon)) {
  12. $blad++;
  13. echo &#092;"<center><b>Komunikat:</b>&nbsp; Zły format danych. Format pola <b>Sezon</b> musi być 0000/0000.<br></center>\";
  14. }
  15.  
  16. if ($blad==0) {...
  17. ?>
Go to the top of the page
+Quote Post
Dabroz
post 24.07.2004, 11:52:45
Post #8





Grupa: Zarejestrowani
Postów: 286
Pomógł: 0
Dołączył: 1.11.2003
Skąd: Poland, Płock

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


Pokręciłeś smile.gif

  1. <?php
  2. $sezon = trim($_POST[&#092;"sezon\"]);
  3.  
  4. if (strlen($sezon)==0) {
  5. $blad++;
  6. echo &#092;"<center><b>Komunikat:</b>&nbsp; Pole <b>Sezon</b> nie może być puste.<br></center>\";
  7. }  else if (ereg(&#092;"[a-zA-Z]\",$sezon)) {
  8. $blad++;
  9. echo &#092;"<center><b>Komunikat:</b>&nbsp; Pole <b>Sezon</b> nie może zawierać liter.<br></center>\";
  10. }
  11.  else if (preg_match('#^d{4}/d{4}$#',$sezon)) {
  12. echo &#092;"JEST DOBRZE! :)\";
  13. }
  14.  
  15. if ($blad==0) {...
  16. ?>


--------------------
Go to the top of the page
+Quote Post
seaquest
post 27.07.2004, 08:49:31
Post #9





Grupa: Przyjaciele php.pl
Postów: 790
Pomógł: 7
Dołączył: 6.02.2003
Skąd: Polska

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


a ja zaproponuje tak:
  1. <?php
  2. ereg('([0-9]{4})/([0-9]{4})',$sezon);
  3. ?>


u mnie działa
tylko w swoim ifie daj !ereg... exclamation.gif!


--------------------
Michał Płachta
Warsztat: Mac OS X Leopard, PostgreSQL, Text Mate, Retrospectiva + SVN
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: 19.07.2025 - 09:49