The code below gives me this mysterious error, and i cannot fathom it. I am new to regular expressions and so am consequently stumped. The regular expression should be validating any international phone number.
Any help would be much appreciated.
function validate_phone($phone) { $phoneregexp ='^(\+[1-9][0-9]*(\([0-9]*\)|-[0-9]*-))?[0]?[1-9][0-9\- ]*$'; $phonevalid = 0; if (ereg($phoneregexp, $phone)) { $phonevalid = 1; }else{ $phonevalid = 0; } }
If this is PHP, then the regex must be enclosed in quotes.
Furthermore, what’spreg? Did you meanpreg_match?Another thing. PHP knows boolean values. The canonical solution would rather look like this:
EDIT: Or, using
ereg:(Here, the explicit test against
FALSEisn’t strictly necessary but sinceeregreturns a number upon success I feel safer coercing the value into abool).