0

I am simply trying to compare a value entered into a form, to ensure it begins with a ? mark.

I have tried suggestions I could find online but can't seem to get it to see when the ? is missing

Any suggestions or direction would be greatly appreciated.

    if(!preg_match("/[\s]*(?)/i", $clean_user_aff_code)){
        $user_aff_code_error = "Your Affiliate code MUST begin with a ?";
        $message = 'Please Correct Highlighted Entry Errors';
    }

    if(!preg_match("/^[[:space:]]*?/i", $clean_user_aff_code)){
      $user_aff_code_error = "Your Affiliate code MUST begin with a ?";
      $message = 'Please Correct Highlighted Entry Errors';
    }

Thanks
Douglas

3
Contributors
3
Replies
16
Views
1 Year
Discussion Span
Last Post by showman13
0

Regular expressions like this can be more difficult to specify than doing something simple and obvious. IE, iterate over the string character by character and the first non-whitespace character has to be '?'. That is what you want, isn't it?

3

Not sure you need a preg for this. Check the first letter of the string, with:

if(substr($clean_user_aff_code, 0 , 1) !== '?'){
    $user_aff_code_error = "Your Affiliate code MUST begin with a ?";
    $message = 'Please Correct Highlighted Entry Errors';
}
Votes + Comments
Short and accurate
1

Thank you diafol... not sure where my head was at.. ( well I could guess, but...)

That will do the trick.

Douglas

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.