Düzenli İfade İle Veri Girişi Doğrulama Kontrol Sınıfı

<?php
class duzenliIfadeKontrol {
	public static function epostaKontrol($metin){
		return self::kontrol($metin,"/^[^@]*@[^@]*\.[^@]*$/");
	}
	public static function ipKontrol($metin){
		return self::kontrol($metin,"/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/");
	}
	public static function hexRenkKontrol($metin){
		return self::kontrol($metin,"/^#[a-fA-F0-9]{6}$/");
	}
	public static function hexNoKontrol($metin){
		return self::kontrol($metin,"/^[a-fA-F0-9]{6}$/");
	}	
	public static function rakamKontrol($metin){
		return self::kontrol($metin,"/^[-+]?\b[0-9]+(\.[0-9]+)?$/");
	}
	public static function sayiKontrol($metin){
		return self::kontrol($metin,"/^[-+]?\b[0-9]*\.?[0-9]+$/");
	}
	public static function kullaniciKontrol($metin){
		return self::kontrol($metin,"/^[a-z\d_]{4,28}$/i");
	}
	private static function kontrol($metin,$kural){
		if (preg_match($kural,$metin))
			return true;
		return false;
	}
}
echo "E-POSTA: ".duzenliIfadeKontrol::epostaKontrol("jordigirones@gmail.com")."<br>";
echo "IP: ".duzenliIfadeKontrol::ipKontrol("192.168.12.31")."<br>";
echo "HEX RENK: ".duzenliIfadeKontrol::hexRenkKontrol("#336AA9")."<br>";
echo "HEX NO: ".duzenliIfadeKontrol::hexNoKontrol("336AA9")."<br>";
echo "RAKAM: ".duzenliIfadeKontrol::rakamKontrol("12345")."<br>";
echo "SAYI: ".duzenliIfadeKontrol::sayiKontrol("12345.6789")."<br>";
echo "KULLANICI: ".duzenliIfadeKontrol::kullaniciKontrol("jgirones");
?>

Çıktısı

E-POSTA: 1
IP: 1
HEX RENK: 1
HEX NO: 1
RAKAM: 1
SAYI: 1
KULLANICI: 1

 

Form Giriş ve Denetim Sınıfı

<?php
Class girisKontrol{
	var $form=null;
	function __construct(){
		$this->form.='<form method="post" action="">';
	}
	function metinKontrol($name,$value,$tut){
		$this->form.='<input type="text" name="'.$name.'" value="'.$value.'" placeholder="'.$tut.'">';
	}
	function sifreKontrol($name,$value,$tut){
		$this->form.='<input type="password" name="'.$name.'" value="'.$value.'" placeholder="'.$tut.'">';
	}
	function metinKutusuKontrol($name,$value,$tut){
		$this->form.='<textarea name="'.$name.'" placeholder="'.$tut.'">'.$value.'</textarea>';
	}
	function onayKutusuKontrol($name,$value){
		$this->form.='<input type="checkbox" name="'.$name.'" value="'.$value.'">';
	}
	function radyoKontrol($name,$value){
		$this->form.='<input type="radio" name="'.$name.'" value="'.$value.'">';
	}
	function butonKontrol($type,$name,$value,$tut){
		$this->form.='<input type="'.$type.'" name="'.$name.'" value="'.$value.'" placeholder="'.$tut.'">';
	}
	function secenekEkle($name){
		$this->form.='<option value="">'.$name.'</option>';
	}
	function listeKontrol($value){
		$this->form.='<select name="">';
		foreach($value as $v){
			$this->form.=$this->secenekEkle($v);
		}	
		$this->form.='</select>';
	}
	function yazdir(){
		$this->form.='</form>';
		return $this->form;
	}
}
$gK = new girisKontrol;
$gK->metinKontrol("abc","","Bir metin giriniz");
$gK->sifreKontrol("abc","","Şifre");
$gK->metinKutusuKontrol("abc","","Birşeyler Yazınız");
$gK->listeKontrol(["Ankara","Aksaray"]);
$gK->onayKutusuKontrol("abcd","");
$gK->radyoKontrol("abc","");
$gK->butonKontrol("button","gonder","Tıkla","");
echo $gK->yazdir();

Çıktısı

<form method="post" action="">
   <input type="text" name="abc" value="" placeholder="Bir metin giriniz"><input type="password" name="abc" value="" placeholder="Şifre">
   <textarea name="abc" placeholder="Birşeyler Yazınız"></textarea>
   <select name="">
      <option value="">Ankara</option>
      <option value="">Aksaray</option>
   </select>
   <input type="checkbox" name="abcd" value=""><input type="radio" name="abc" value=""><input type="button" name="gonder" value="Tıkla" placeholder="">
</form>