I have JavaScript validation on my form that checks to see that the default value in the message field is not being submitted, however i want to add the same validation in PHP Here is my JavaScript validation if ((numofchar<1) || (numofchar>500) || value.indexOf('(Please fill in this field)')!=-1) HTML: so this makes sure that the user cannot enter "Please fill in this field" in the message field AND they cannot enter "Please fill in this field asasdad" in the message field I want the add the same validation in PHP Here is what i currently have in my PHP validation: if ((strlen( $about_me) < 1 || strlen( $about_me) > 500 )) PHP: Can someone please help me add a PHP version of the JavaScript validation above so that it checks to see if the string "Please fill in this field" is in the string trying to be submitted, thanks
you would just add the following code: preg_match("Please fill in this field", $about_me); Code (markup): so your code would look like this: $text = "Please fill in this field"; if ((strlen( $about_me) < 1 || strlen( $about_me) > 500 ) && preg_match($text, $about_me)) Code (markup): That will make it fail if it finds $text or "Please fill in this field", otherwise it will continue on.
the literal translation of that line is if( ( strlen( $string ) < 1 || strlen( $string ) > 500 ) || strpos( $string, '(Please fill in this field)' ) !== false ) PHP:
if ((strlen( $about_me) < 1) || (strlen($about_me) > 500) || !strcmp($about_me,"Please fill in this field")) { //code } PHP: