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? Quote 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 } Quote 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 } Quote 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'; ?> Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.