Twitsnip is a place to post code snippets and share them. Login with your existing Twitter account, if you don't have a Twitter account simply create on at www.twitter.com

PHP function to check lenght of string

PHP function to check lenght of string

0

This was the first function I ever wrote and I still use it in nearly every PHP application I create.

function checkLength($name, $low, $high, $which) {

	global $error; // This global returnes any errors out of the function
	
	if (strlen($name) < $low) {
	
	$error[] = "<b>{$which}:</b> Must be between {$low} and {$high} characters."; }
	
	if (strlen($name) > $high) { 
	
	$error[] = "<b>{$which}:</b> Must be between {$low} and {$high} characters."; }
	
	}

Tags: validation, form, functions

Comments

No comments yet

Login to Twitter to comment