Location: PHPKode > scripts > Formcat Class > formcat-class/pro/validators/js_validator_isFileType.php
<?
 /**
   * Javascript validator for "isFileType" check
   * Perform the validation of "isFileType" check
 
   * @param array    $params   params set including following parameters:	
   *                           string   $field    Field to test
   *						   string   $type     Type to check (,devide)
   *                           bool     $focus    If error whether focus on the input element (optional)
   * @return string JS function body
   **/ 		
   function js_validator_isFileType(&$formcat,$params){
   		extract($params);
   		$message = (empty($message))?sprintf($formcat->defaultErrMsg,$field):$message;
   		$focusStr = $formcat->addFocus($field,$focus);
   		if($field!='' && $type!=''){  		
	   		$title = "\n\n //checks file type.\n";
	   		if(!empty($type)) $type = str_replace(',','|',$type);
	       	$body = "var reg = new RegExp('(".$type.")');\n".
	        $body.=($optional)?"if((fc['".$field."'].value!='') && (!reg.test(fc['".$field."'].value)) && (!confirm('$message'))){\n":"if((fc['".$field."'].value!='') && (!reg.test(fc['".$field."'].value))){\nalert('$message');\n";
				  
	   	    $str= $title.$body.$focusStr."return false;\n}\n";		
	        return $str;
	    }
    }



?>
Return current item: Formcat Class