tclogo



HotelsCombined.com

Pages

Archives

Categories


Recent Postings

Recent Comments

Feeds

RSS2 feed

Links

Most Popular Posts

Validating textboxes/combos

Wednesday, 22nd March 2006 12:08pm
I have been working on a form where I have Php server side validation for field lengths for all the textboxes and combo boxes on a form. Normally I would have written a function for each of the textboxes but in this case there were 7 and so I had to think of a better way to do it. So I came up with this function:


function ValidateField($strField,$strEntry, $intMin, $intMax){
if(trim($strEntry)=='' || strlen(trim($strEntry)) <$intMin || strlen(trim($strEntry)) > $intMax) {
echo "Please enter a $strField between $intMin and $intMax characters" ;
}
return true;
}


So say for a product textbox with a minimum length of 2 and maximum of 20 characters, I would validate like this:


ValidateField("Product",$strProduct, 2,20);


and then go on to the next one say product code:


ValidateField("Product Code",$strProductCode, 3,4);


and so on.

Post a comment:

 

(required)

(required, but not published)

(optional)





Notify me of follow-up comments via e-mail