Darkmatter5 Posted May 27, 2008 Share Posted May 27, 2008 How would one check if a text box is empty or has a value entered? Link to comment https://forums.phpfreaks.com/topic/107471-solved-how-to-check-if-a-text-box-is-empty-or-has-a-value-entered/ Share on other sites More sharing options...
pocobueno1388 Posted May 27, 2008 Share Posted May 27, 2008 <?php $textarea = trim($_POST['field_name']); if ($textarea == ""){ //textbox was empty } else { //textbox has a value } Link to comment https://forums.phpfreaks.com/topic/107471-solved-how-to-check-if-a-text-box-is-empty-or-has-a-value-entered/#findComment-550860 Share on other sites More sharing options...
ILYAS415 Posted May 27, 2008 Share Posted May 27, 2008 To check if a text box is empty... if ($_POST['textboxname'] == NULL){ //if nothing is entered or only a zero is entered echo "error missing field you noob"; }else{ //rest of code } and to check if a text box has something inside it... if (strip_tags($_POST['textboxname'])){ //if textboxname has a value entered //code } Link to comment https://forums.phpfreaks.com/topic/107471-solved-how-to-check-if-a-text-box-is-empty-or-has-a-value-entered/#findComment-550861 Share on other sites More sharing options...
sasa Posted May 27, 2008 Share Posted May 27, 2008 or <?php $a = ' '; if (preg_match('/\S+/',$a)) echo 'not empty'; else echo 'empty'; ?> Link to comment https://forums.phpfreaks.com/topic/107471-solved-how-to-check-if-a-text-box-is-empty-or-has-a-value-entered/#findComment-550864 Share on other sites More sharing options...
ILYAS415 Posted May 27, 2008 Share Posted May 27, 2008 I hate regex Link to comment https://forums.phpfreaks.com/topic/107471-solved-how-to-check-if-a-text-box-is-empty-or-has-a-value-entered/#findComment-550868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.