0

I have the following code block for validation in PHP and I can't figure out why my validation is still failing. I am a newbie to regular expressions but I want to allow for ($ , . -) but it isn't working. I started out with "[A-Za-z0-9]". The only character that is allowed with the below code is the dash (-) but not $ or . or , or space. Can someone point me in the right direction?

case 'alnum':
{
        $bret= $this->test_datatype($input_value,"[A-Za-z0-9\s$,.-]");
        if(false == $bret) {
            $default_error_message = sprintf(E_VAL_ALNUM_CHECK_FAILED,$variable_name);
        }
    break;
                            }
1
  • You should use preg_match right there and not obfuscate it with an interception method. (Which, its inner workings being unknown, makes this hard to answer). The false== comparison is also super redundant. Commented Apr 7, 2012 at 3:43

1 Answer 1

1

You can use backslash before characters that are not working i.e. $ etc.

$bret= $this->test_datatype($input_value,"[A-Za-z0-9\s\$\,\.-]");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.