Home > Software engineering >  a function is giving me an error about a comma
a function is giving me an error about a comma

Time:12-18

function emptyInputSignup($fname, $lname, $email, $username, $pwd, $pwdrepeat) {
    $result = null;
    if (empty($fname) || empty($lname) || empty($email) || empty($username) || empty($pwd) || empty($pwdrepeat)) {
        $result = true;
    } else {
        $result = false;
    }
    return $result;
};
function invalidUid($username) {
    $result = null;

    if (!preg_match('/^[a-zA-Z0-9]*$/'), $username) {
        $result = true;
    } else {
        $result = false;
    }
    return $result;

}

What have I donr wrong, what does it want, i literally copied the emptyInputSignup function and then wrote some regex in and vscode is confused

I've stared at it for an hour, when I google for regex not working properly, I couldn't find anyone having similar problems.this is the error I'm getting

CodePudding user response:

You need to put , $username inside the preg_match function parenthesis, after the regex pattern. It is in the wrong place.

It should be:

if (!preg_match('/^[a-zA-Z0-9]*$/', $username)) {
    $result = true;
} else {
    $result = false;
}
  • Related