input validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leeo
Forum Newbie
Posts: 4
Joined: Mon Nov 25, 2002 10:08 am

input validation

Post by leeo »

elo are there any good functions to aid in validation

like in C i use isalpha() and in java i can use isLetter()

i have my variable as a string but how can i turn this into an array to deal with character validation just some good pointers required as i know the theory just not the good functions to use

on this note any good places to find out this info, some reference or summit like java docs gives me.

all help welcome
o yes im new to php :lol:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The PHP manual is always a good place to start:
http://www.php.net/manual
http://www.php.net/manual/en/ref.variables.php

Mac
leeo
Forum Newbie
Posts: 4
Joined: Mon Nov 25, 2002 10:08 am

Post by leeo »

ty m8 good bit of help im now stuck though

Code: Select all

function isLengthWithinRange($input_string, $max_length, $min_length){
   $sof = count($input_string);
  
   if($sof>$max_length || $sof < $min_length)&#123;
      echo "size out of bounds<br>";
      echo $sof;
      return FALSE;
   &#125;
   else&#123;
      return TRUE;
   &#125;
&#125;
as you can see im trying to validate range (sof) seems to always be 1 i thought the count() function returned the number of elements in the input_string variable.

what am i doing wrong?
also a little explaining as to hoe this conversion is achieved although this is probs the answer hehe.

Leeo
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Try using the strlen() function instead of count.

http://www.php.net/manual/en/function.strlen.php

Enjoy! 8)
leeo
Forum Newbie
Posts: 4
Joined: Mon Nov 25, 2002 10:08 am

Post by leeo »

Thats what i like straight forward replies works a treat ty m8
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post by BigE »

You still might be interested in checking out the manual. I suggest checking out empty() php.net/empty and is_string() php.net/is_string They are both good for validation purposes.
leeo
Forum Newbie
Posts: 4
Joined: Mon Nov 25, 2002 10:08 am

Post by leeo »

n1 lads ive added those extra 2 now :)

i am looking at the manual but it takes a while to get into it didnt even notice the string functions at first :)

starting to enjoy this php still havent mastered the class yet :oops:

Leeo
Post Reply