janka Posted March 16, 2004 Report Share Posted March 16, 2004 lūdzu pasakiet, kā var izdarīt, lai gadījumā, ja lietotājs formā grib ierakstīt kaut ko citu nevis skaitļus, lai izmet kļūdas paziņojumu? ideālajā variantā vajadzētu, lai skaitļus būtu iespējams nodot tikai konkrētā formā, piemēram, kā IP adresi 1.2.3.4 Link to comment Share on other sites More sharing options...
trinklins Posted March 16, 2004 Report Share Posted March 16, 2004 (edited) <?php function is_num($var) { for ($i=0;$i<strlen($var);$i++) { $ascii_code=ord($var[$i]); if ($ascii_code >=49 && $asci_code <=57) continue; else return false; } return true; } //$mainigais = asd; $mainigais = 123; if (is_num($mainigais) == true) { echo "Nav skaitlis"; } else { echo "Ir skaitis"; } ?> mazliet ar manuāli vajag parotaļāties :lol: :lol: bet par ip ---> baigi daudz jāraksta netīkās :D Edited March 16, 2004 by trinklins Link to comment Share on other sites More sharing options...
bubu Posted March 16, 2004 Report Share Posted March 16, 2004 nu helpu taksh jaamaak lasiit! vai tad tik gruuti katru stringa simbolu paarbaudiit, vai tas ir digit vai nee? kur shitaadi programeetaaji rodas, kas manuaaljus nelasa!!? Link to comment Share on other sites More sharing options...
Venom Posted March 16, 2004 Report Share Posted March 16, 2004 function test() { var match=new RegExp([0-9]); if (!match.test(document.form.tikai_numuri)) alert('gļūks'); } utt. Link to comment Share on other sites More sharing options...
Gacha Posted March 27, 2004 Report Share Posted March 27, 2004 jautājums, kapēc nevar izmantot prosta šitādu f-cju function skaits($f){ if(is_numeric($f)){$b = $f + 10;}else{$b = 'Tas nav skaitlis';} return $b; } ??? Kapēc jalieto tik daudz? Kāda ir atšķiriba? Offtopic: Kā te forumā var ievietot kodu, lai tas būtu krāsains? No 20 postiem 1 esmu tā redzējis!!! Link to comment Share on other sites More sharing options...
hu_ha Posted March 27, 2004 Report Share Posted March 27, 2004 aaaaaaaaaaaa liec tagu un attieciigi aizverosho tagu :) Link to comment Share on other sites More sharing options...
Gacha Posted March 28, 2004 Report Share Posted March 28, 2004 Nu tu laikam mani par galīgi stūlbu uzskati :P ka pat krasainu textu nevaru ielikt !!! Es biju domājis, kā var dabūt koda Hailaitingu ??? Bet galvenais gribeju dzirdēt atb uz 1 jautajumu. Link to comment Share on other sites More sharing options...
rnc Posted March 28, 2004 Report Share Posted March 28, 2004 Gacha: cik man zinaams, tad funkcija is_numeric atgrieziis arii TRUE ja buus piemeeram shaada simbolu virkne 1332zb343 :) Vieniigais tad vareetu sakombineet kaut ko shitaadu ar taas f-jas is_numeris() paliidziibu: <?php function ir_skaitlis($strings) { $check = TRUE; for($m=0;$m<=strlen($strings);$m++) { if (!is_numeric($strings[$m]) || $strings[$m] != ".") { break; $check = FALSE; } } } ?> Link to comment Share on other sites More sharing options...
Aleksejs Posted March 28, 2004 Report Share Posted March 28, 2004 Ja iet runa par INTEGER, tad var arī šādu pārbaudi: <?php function irinteger($str){ if(($str.'k')==(intval($str).'k'))[ return true; else { return false; } } Link to comment Share on other sites More sharing options...
Gacha Posted March 28, 2004 Report Share Posted March 28, 2004 Kas tas pa k ? Link to comment Share on other sites More sharing options...
Aleksejs Posted March 28, 2004 Report Share Posted March 28, 2004 'k' lai būtu drošs, ka string tips tiks iegūts galā... Tas adoptēts no shellskriptiem. Nezinu, varbūt var iztikt bez... Link to comment Share on other sites More sharing options...
Recommended Posts