Search code examples
phphtmlsyntax-error

Where is the error in my code? syntax error, unexpected token "," (PHP)


I am a total beginner on PHP so that is why I can't find what the error is... it seems very simple but I can't find it, this is the part of my code that is giving me trouble:

function invalidRUT($username) {
$result;
if (!preg_match("/^[0-9]*$/"), $username) {
    $result = true;
}
else {
    $result = false;
}
return $result;
}

And the error message is: syntax error, unexpected token "," (lin 15, col.5)


Solution

  • Try this: (fixed code)

    function invalidRUT($username) {
    $result;
    if (!preg_match("/^[0-9]*$/", $username)) {
        $result = true;
    }
    else {
        $result = false;
    }
    return $result;
    }