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 1916 korisnika na forumu :: 55 registrovanih, 4 sakrivenih i 1857 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: A.R.Chafee.Jr., aleksmajstor, Arhiv, Bojan198527, BORUTUS, darionis, DejanSt, dekan.m, djordjemiklusev, DonRumataEstorski, draganca, dule10savic, duro1990duro, Dzoni2412, Electron, eulereix, FileFinder, ginjica, Giskard, GT, ikan, Kalem, Komentator, laurusri, littlebunny, M74AB3, MagicniHerpes, marko308, MarkoD, mercedesamg, Metanoja, miki kv, milenko crazy north, Miler88, mishkooo, mnn2, Ne doznajem se u oružje, nelezele, Nemanja Opalić, nezavisni mislilac, Obrenovic, Orc, ozzy, Paklenica, Polemarchoi, Resnica, Sevatar, Sirius, VJ, Vlada1389, vladulns, Weah88, zdrebac, zexon, Zoran1959