brent123456 Posted June 22, 2007 Share Posted June 22, 2007 I have a javascript function set up to check characters as they are being typed. I was wondering how I would check the $_POST[foo] variable to make sure that it is less then say 50 character on submit in case javascript is turned off? Thanks Link to comment https://forums.phpfreaks.com/topic/56717-checking-characters-in-a-string/ Share on other sites More sharing options...
pocobueno1388 Posted June 22, 2007 Share Posted June 22, 2007 <?php if (strlen($_POST['foo'] > 50)){ echo "Foo is too long!"; } else { echo "Foo is a good length....continue."; } ?> Link to comment https://forums.phpfreaks.com/topic/56717-checking-characters-in-a-string/#findComment-280131 Share on other sites More sharing options...
brent123456 Posted June 22, 2007 Author Share Posted June 22, 2007 thank you Link to comment https://forums.phpfreaks.com/topic/56717-checking-characters-in-a-string/#findComment-280133 Share on other sites More sharing options...
brent123456 Posted June 23, 2007 Author Share Posted June 23, 2007 if (stripslashes(trim($_POST['discription']) && (strlen($_POST['discription'] < 75)))) { $d = escape_data($_POST['discription']); print strlen($_POST['discription']) ; } else { $d = false; echo '<p><font color="red" size="+1">Please enter your Feedback!</font></p>'; } This doesn't seem to be validating is there something wrong with my code? Even when $_POST['discription'] is more then 75 characters it is not going to the else option. Link to comment https://forums.phpfreaks.com/topic/56717-checking-characters-in-a-string/#findComment-280594 Share on other sites More sharing options...
pocobueno1388 Posted June 23, 2007 Share Posted June 23, 2007 Try this: <?php $description = stripslashes(trim($_POST['discription'])); if (strlen($description) < 75) { //If description is LESS than 75 chars $d = escape_data($description); //I'm assuming escape_data() is a function you wrote? print strlen($description); } else { //Do this if description is MORE than 75 chars $d = false; echo '<p><font color="red" size="+1">Please enter your Feedback!</font></p>'; } ?> Link to comment https://forums.phpfreaks.com/topic/56717-checking-characters-in-a-string/#findComment-280602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.