Grey_Wolf Posted October 1, 2005 Report Share Posted October 1, 2005 Mazliet nonaacu strupceljaa :( vajag stringa parbadi kas satur n (piemeeram 4) atljautos simbolus Jebkuraa seciibaa.... piem: $a='āaš12'; // true $a='abcā#'; // true $a='āšč' // false ------ ^[a-z0-9A-Z_] tiktaal viss skaidrs: ja raksta shaadi ^[a-z0-9A-Z*]+ arii 1 atljautais simbols ir valiids ja + aizvieto {skaits} tad parbauda vai atljautie simb iet peec kaartas , vajadzeetu la buutu dotais skaits Jebkuraa seciibaa Kaadas idejas? P.S. izmekleejos gan netaa (nu visu jau nav iespeejams izskatiit) gan sheit (biezaak uzdotajos jautaajumos jau izskatiju) Link to comment Share on other sites More sharing options...
bubu Posted October 1, 2005 Report Share Posted October 1, 2005 Nesaprotu ko tev vajag. Ja vajag pārbaudīt vai strings sastāv precīzi no 4 noteiktiem simboliem, tad: if (preg_match('#^[\d\w_]{4}$#i', $text)) { // ir ok } else { // nav ok } Kur tajās [...] iekavās ieliec atļautos simbolus. Link to comment Share on other sites More sharing options...
Grey_Wolf Posted October 1, 2005 Author Report Share Posted October 1, 2005 Nesaprotu ko tev vajag. 23605[/snapback] Vajag noteikt vai stringaa ir 2 Latinju simboli ( A-Za-z0-9_ ) vai nav - nenjemot veeraa paareejos simbolus - pie tam vinji var buut jebkuraa seciibaa - piem: Jāņis - valiids // 3 simboli Jāņš - nav valiids // 1 simbols -------- Link to comment Share on other sites More sharing options...
bubu Posted October 1, 2005 Report Share Posted October 1, 2005 if (preg_match('#^(.*\w){2}.*$#i', $text)) { // ir ok } else { // nav ok } Link to comment Share on other sites More sharing options...
Grey_Wolf Posted October 1, 2005 Author Report Share Posted October 1, 2005 if (preg_match('#^(.*\w){2}.*$#i', $text)) { // ir ok } else { // nav ok } 23610[/snapback] paldies shis gandriiz dereeja mazliet pielaboju '/w' vietaa '[A-Za-z09_]' Link to comment Share on other sites More sharing options...
bubu Posted October 1, 2005 Report Share Posted October 1, 2005 Tu jau prasīji latīņu simbolus.. Ja tev vajag [a-zA-Z0-9_] tad vajag šitā: preg_match('#^(.*[\w\d_]){2}.*$#i', $text) Link to comment Share on other sites More sharing options...
Klez Posted October 2, 2005 Report Share Posted October 2, 2005 Tu jau prasīji latīņu simbolus.. Ja tev vajag [a-zA-Z0-9_] tad vajag šitā: preg_match('#^(.*[\w\d_]){2}.*$#i', $text) 23625[/snapback] bubu, vari izskaidrot ito postu? ko noziimee: '#^(.*[\w\d_]){2}.*$#i' tas visss?? kaut mazliet B) Link to comment Share on other sites More sharing options...
bubu Posted October 2, 2005 Report Share Posted October 2, 2005 #X#Y - # atdala patternu X no modifieriem Y ^ - norāda teksta sākumu $ - norāda teksta beigas (X){2} - norāda, ka patternam X obligāti jābūt divas reizes pēc kārtas .* - nozīmē jebkurus simbolus jebkurā skaitā (arī 0) [\w\d_] - nozīmē vienu jebkuru simbolu a-z vai 0-9 vai _ (\w=a-z, \d=0-9 modifieris i - nozīmē case insensitivity, tb a atbildīs gan a, gan A. (sintakse jau vispār jāskatās php manuālī, bet nu...) Link to comment Share on other sites More sharing options...
Klez Posted October 2, 2005 Report Share Posted October 2, 2005 tnx bubu :) ;) Link to comment Share on other sites More sharing options...
Delfins Posted October 2, 2005 Report Share Posted October 2, 2005 tas taku php-manuālī ir viss... ko nozīmē katra `birka`... mmm Link to comment Share on other sites More sharing options...
rpr Posted October 3, 2005 Report Share Posted October 3, 2005 shjajaa variantaa gan nestraadaaas variants, ja buus "ādķs", kas peec nosacijumiem arii vareetu buut. taadaa gadiijumaa labaak iziet cuari visam tekstam ar ciklinju. Link to comment Share on other sites More sharing options...
bubu Posted October 3, 2005 Report Share Posted October 3, 2005 Pastāstīsi, kāpēc lai tas nestrādātu tavā gadījumā? Link to comment Share on other sites More sharing options...
rpr Posted October 3, 2005 Report Share Posted October 3, 2005 man likaas, ka {2} ir peec kaartas, bet nu izskataas, ka es esmu noignoreejis pirmos .* Link to comment Share on other sites More sharing options...
Delfins Posted October 3, 2005 Report Share Posted October 3, 2005 {} ir atkārtošanās reizes/garums {,2} = 0 .. 2 {2} = 2 {2,} = vismaz 2 Link to comment Share on other sites More sharing options...
Delfins Posted October 3, 2005 Report Share Posted October 3, 2005 tev tas ^ ir obligāts? vnk '#^(.*[\w\d_]){2}.*$#i' => '#([\w\d_]){2}#i' ir vienkāršāk (ja jau jebkurā secībā) Link to comment Share on other sites More sharing options...
Recommended Posts