hi. i have this two variables in my script:

$name
$surname

and i have a form where users enter their name and surname. what i want is that when they enter their name and surname, they do not put any space! something like

John Paul <----- wrong!
JohnPaul or John_Paul <------- ok!

if they do they should be prompted with "pls do not put space in name or surname". what code do i insert to have this kind of validation? i have something to validate the email format:

if (!preg_match("/.*@.*..*/", $_POST['email']) | preg_match("/(<|>)/", $_POST['email'])) {

how do i do the same for the above question? thanks

    if(strpos($name.$surname, " ") !== FALSE){
       echo "Error: No spaces allowed!";
       exit;
    }

      Actually, it should be:

      if (strpos($name.$surname, " ") !== false) {
      	echo "Error: No spaces allowed!";
      	exit;
      }

        Leave it to me to write it ass-backwards.

          There's a problem with comparing to true as well - a single space at the start will still be accepted since 0 != true

            I was just about to ask if there was a "difference" in using !== false and == true.

            That answers that...

            Thanks.

            🙂

              Write a Reply...