basic validation

basic validation

offline
  • Blood  Male
  • Ugledni građanin
  • Pridružio: 26 Jul 2003
  • Poruke: 384
  • Gde živiš: Beograd

Za sve kojima treba neka prosta validacija a nece da je traze po netu, mogu koristiti ovu klasu...

Dovoljno je samo instancirati objekat i pozvati metodu check.

Metoda check prima 2 parametra, prvi je string koji zelite da proverite, a drugi moze biti ili neka od rezervisanih reci za koje je vec napisan regularni izraz, ili sam regularni izraz..

<?php /**  * Copyright (C) 2008 Boban Karišik <karisikb@gmail.com>  *  * This program is free software; you can redistribute it and/or  * modify it under the terms of the GNU General Public License  * as published by the Free Software Foundation; either version 2  * of the License, or (at your option) any later version.  *  * This program is distributed in the hope that it will be useful,  * but WITHOUT ANY WARRANTY; without even the implied warranty of  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  * GNU General Public License for more details.  *  * You should have received a copy of the GNU General Public License  * along with this program; if not, write to the Free Software  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.  */ class Validate {     var $email      = '/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/s';     var $phone      = '/[0-9\-\/]{6,15}\s/';     var $url        = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&amp;?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/s';     var $username   = '/^[a-z\d_]{5,20}$/i';     var $image      = '/(\.gif|\.jpg|\.png)$/i';     var $ip         = '/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/s';     var $hexColor   = '/#([a-fA-F0-9]{3})|([a-fA-F0-9]{6})$/';     var $date       = '/\d{1,2}(\.|\/)\d{1,2}(\.|\/)(\d{2}|\d{4})(\.|$)$/';     var $empty      = '/.+/';     var $regEx;             /**     * Check an string for regular expression matches     *     * @param string $string - String you want to check     * @param string $exp - Regular expression or reservated word (email, phone, url, username, image, ip, hexCode, date, empty)     */     function check($string, $exp = 'empty') {                $this->regEx    = ($this->$exp != '') ? $this->$exp : $exp;         return preg_match($this->regEx, $string);     }     } ?>

Primer
$val = new Validate(); if($val->check('some@email.net','email')) {   echo 'true'  ; } else {   echo 'false'; }

p0z



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 2092 korisnika na forumu :: 91 registrovanih, 10 sakrivenih i 1991 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 20624 - dana 04 Apr 2026 04:18

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: acatomic, alternator, AS, Asteker, bambulic, Bane san, Bbbggg1979, BBCRF, Besudna, bigbear, Bojke549, bolenbgd, boromir, branko7, Burovnyak, Car89, Dare, darkdruid72, darkojovxp, dejan.lxxiv, dekan.m, Denaya, DezurniOperativni, dimitrije.muzur, Dioniss, dnevnasoba, DonRumataEstorski, Draganeli, Duk011, Dusko_Dugousko, Dzambas, Electron, Fliper, gajasvi, Georgius, ginjica, Giskard, Hans Gajger, Haris, HogarStrashni, Jaz, Jeremiah, K a s p e r, Kajzer Soze, KimiMR, Komder, lacko, lanishtefm, Lazarus, lcc, Levi, Lieutenant, Litostroton, luka35, Matija, mačković, mercedesamg, mikidragi, Milan A. Nikolic, milos1231, Mićko, MK10, N.e.m.a.nj.a., Nepopravljivi, Njubara, oganj123, Orc, Paklenica, pein, Pekman, radza1, Ran, raptorsi, read-only, sap, SD izvidjac, Srki98, Srna, toshevski, US_Rank_0, vargas, vathra, Vatreni Zmaj, Veless, vidra1, vrgudinac, wolverined4, zauzet, ZetaMan, Zrcalo, 79693