Webdetector Webmaster Forums - Your favorite webmaster community
 

Advertise Here Wordpress Premium Sportscrazyforum - Where Sport is a religion dnfame.com Spruce Host chooseapixel.com

Go Back   Webdetector Webmaster Forums - Your favorite webmaster community > Developers Corner > Programming > PHP Forum

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-03-2008, 05:54 AM
Member
noobee
 
Join Date: May 2008
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default help please with a php function/general regex help?

php function doesnt seem to be working.....
Question Details:I am trying to validate php form data, ideally I want to ensure that the text field has no whitespaces, and has a min AND max range.
Code:
<?php
require ('config.php');
$username=$_POST['usernam...
$offence=$_POST['offence'...
$punishment= $_POST['punishment'];
$database=naughtylist;
$table=naughty;
$min=1;
$max=15;


function checkLength($username, $min, $max) {
$length = strlen ($username);
if (($length < $min) || ($length > $max)) {
return FALSE;
} else {
return TRUE;
}
}
That code doesnt work....even when I leave the field blank, I do not get any errors/feedback etc.

If anyone can help me with regex in php generally or suggest a more efficient method of doing this then thanks.

Ive made a validation script in javascript, but I am wanting the php validation for an extra layer of protection.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)  
Old 06-04-2008, 07:06 PM
Super Moderator
noobee
 
Join Date: Jun 2008
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default help please with a php function/general regex help?

Try this.

Code:
function checkLength($username, $min, $max) {
$username = strip_tags($username);
$username = trim($username);

$length = strlen ($username);
if (($length < $min) || ($length > $max)) {
return FALSE;
} else {
return TRUE;
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 12:32 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Ad Management by RedTyger