<?php
 	
	class valid{
		
        static $list_error = array(
            'phone' => 'Incorrect phone number format in field <b>{name}</b>',
            'price' => 'Incorrect price format in field <b>{name}</b>',
            'filesize' => 'Incorrect file size format in filed <b>{name}</b>, correct format: 0.00',
            'mobile' => 'Incorrect phone number format in field <b>{name}</b>',
            'email' => 'Incorrect email address in field <b>{name}</b>',
            'lineBreak' => 'In field <b>{name}</b> too long character strings are appearing',
            'www' => 'Incorrect URL Address in field <b>{name}</b>',
            'login' => 'Incorrect login name in field <b>{name}</b> ',
            'perfect_money' => 'Enter correct <strong>Perfect Money</strong> account',
            'solid_trust_pay' => 'Enter correct <strong>SolidTrustPay</strong> account',
            'std_name' => 'Field <b> {name} </b> can contain exclusively alphanumeric characters, sign of the dash and the space',
            'std_chars' => 'Incorrect value in field <b> {name} </b>',
            'num' => 'Incorrect value in field <b> {name} </b>',
            'tag' => 'Incorrect Tag Name in field: {name}',
            'postcode' => 'Incorrect post code in field <b>{name}</b>',
            'clear_name' => 'Field <b> {name} </b> can contain exclusively alphanumeric characters'
        );
        
		public static function email( $input ){	
	        if(preg_match( "#[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})#",$input) ){
	            return true;
	        } else {    
	            return false;
	        }				
		}

		public static function price( $input ){	
			if(stristr( $input , '.' )){
				$parts = explode( '.' , $input );
				if(valid::num($parts[0]) and valid::num($parts[1]) and strlen($parts[1])==2) return true;
				else return false;
			} else return false;
		}

		public static function longprice( $input ){	
			if(stristr( $input , '.' )){
				$parts = explode( '.' , $input );
				if(valid::num($parts[0]) and valid::num($parts[1]) and strlen($parts[1])<=4) return true;
				else return false;
			} else return false;
		}
                
		public static function fsize( $input ){	
			if(stristr( $input , '.' )){
				$parts = explode( '.' , $input );
				if(valid::num($parts[0]) and valid::num($parts[1]) and strlen($parts[1])==2) return true;
				else return false;
			} else return false;
		}
               	
		public static function www( $input ){
		    if(preg_match( "#http(s)?:\/\/(www\.)?([.a-zA-Z0-9]*)?([a-zA-Z0-9]*)+\.([a-zA-Z]{2,4})+#" , $input ) ){
		        return true;
		    } else {
		    	return false;
		    }	
		}
        
		public static function mobile( $input ){
		    if(preg_match( "#^([0-9\s\.\+])+$#" , $input ) ){
		        return true;
		    } else {
		    	return false;
		    }	
		}

		public static function login( $input ){
			
			if(preg_match( "#^([A-Za-z0-9_]+)$#i", $input )){
				return true;
			} else {
				return false;
			}
			
		}
		
		public static function std_name( $input ){
			if(preg_match("#^([A-Za-z0-9ąĄżŻśŚźŹęĘćĆńŃóÓłŁ\-\s]+)$#",$input)) return true;
			else return false;
		}

		public static function street( $input ){
			if(preg_match("#^([A-Za-z0-9ąĄżŻśŚźŹęĘćĆńŃóÓłŁ\-\s\'\/]{3,})$#",$input)) return true;
			else return false;
		}

		public static function city( $input ){
			if(preg_match("#^([A-Za-z0-9ąĄżŻśŚźŹęĘćĆńŃóÓłŁ\-\s\']{3,})$#",$input)) return true;
			else return false;
		}
                
		public static function dir_name( $input ){
			if(preg_match("#^([A-Za-z0-9ąĄżŻśŚźŹęĘćĆńŃóÓłŁ\-_]{1,50})$#",$input)) return true;
			else return false;
		}
        
		public static function std_chars( $input ){
			if(preg_match("#^([A-Za-z]+)$#",$input)) return true;
			else return false;
		}

		public static function std_chars_and_digits( $input ){
			if(preg_match("#^([a-zA-Z0-9]+)$#",$input)) return true;
			else return false;
		}
                
        public static function perfect_money( $input ){
			if(preg_match("#^U([0-9]+)$#",$input)) return true;
			else return false;
        }

        public static function solid_trust_pay( $input ){
			if(preg_match("#^([a-zA-Z0-9]+)$#",$input)) return true;
			else return false;
        }
                	
		public static function num( $input ){
			if(preg_match( "#^[0-9]+$#" , $input )) return true;
			else return false;
		}

        public static function tag( $input ){
			if(preg_match("#^([A-Za-z0-9ąĄżŻśŚźŹęĘćĆńŃóÓłŁ\s,]+)$#",$input)) return true;
			else return false;
        }
   
	
		public static function gg( $input , $chars = 10){
			if(preg_match( "#^[0-9]+$#" , $input ) and strlen($input) <= $chars) return true;
			else return false;
		}
				
		public static function postcode( $input ){
			if(preg_match( "#^([a-zA-Z0-9\s\-]{3,})$#" , $input ) ) return true;
			else return false;
		}		 

		public static function clear_name( $input ){
			
			if(preg_match( "#^([a-zA-Z0-9\sąęóśłżźćńĄĘÓŚŁŻŹĆŃ]+)$#" , $input ) ) return true;
			else return false;
			
		}

	 	public function nip( $input ){
	 		
			if (strlen( $input ) != 10)
			{
				return false;
			}
		 
			$arrSteps = array(6, 5, 7, 2, 3, 4, 5, 6, 7);
			$intSum=0;
			for ($i = 0; $i < 9; $i++)
			{
				$intSum += $arrSteps[$i] * $input[$i];
			}
			$int = $intSum % 11;
		 
			$intControlNr=($int == 10)?0:$int;
			if ($intControlNr == $input[9])
			{
				return $input;
			}
			return false;
	 	}
        
		public static function date( $input ){
			if(stristr($input,'-')){
				$tmp = explode( '-' , $input );
				if(count($tmp)==3){
					if(strlen($tmp[0])==4 and (strlen($tmp[1])==2 or strlen($tmp[1])==1) and (strlen($tmp[2])==2 or strlen($tmp[2])==1)){
						if(valid::num($tmp[0]) and valid::num($tmp[1]) and valid::num($tmp[2])) return true;
						else return false;
					}
				} else return false;
			} else return false;
		}
				
		

		
		public static function lineBreak( $text , $chars = 50 ){
			if(stristr($text," ")){
				$tmp = @explode(" ",$text);
				foreach( $tmp as $item ){
					if(strlen($item)>$chars){
						return false;
						break;
					}
				}
			} else {
				if(strlen($text)>$chars) return false;
			}
			
				return true;
		}
        
			
	}

?>