I'd like to get some help regarding PHP. Let's say I have a string ($fullname). I want to validate that it's in the form of "Firstname_Lastname". For example, make sure that it's "Nathan_Phillips" and not "Nathan Phillips" or "Nathan122" etc. Can you guys help me with the function?
Thanks in advance! :-)
------------ EDIT ------------- Thank you guys! Managed to do that. Also added the numbers filter. Here's the function:
function isValidName($name)
{
if (strcspn($name, '0123456789') != strlen($name))
return FALSE;
$name = str_replace(" ", "", $name);
$result = explode("_", $name);
if(count($result) == 2)
return TRUE;
else
return FALSE;
}
Usage example:
if(isValidName("Test_Test") == TRUE)
echo "Valid name.";
else
echo "Invalid name.";
Thanks again!