Jump to content

[SOLVED] Simple Validation


phpretard

Recommended Posts

What i can think of is using explode() and count if there are 2 values on the array:

 

<?php
$input = 'John Smith';
$name = explode(' ', trim($input)); //trim() input if u have "John " or " John"
if(count($name) == 2){ //if $name array has two values
     $pass = 'yes';
} else{
     $pass = 'no';
}
?>

 

or just see if there's any space:

 

<?php
$input = 'John Smith';
if(strstr(trim($input), ' ')){  //if there is a space between the text
    $pass = 'yes';
} else{
    $pass = 'no';
}
?>

 

I would prefer the first anyway.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.