First, use
$query="UPDATE table SET phone='NULL' WHERE phone NOT REGEXP '^\+?[0-9]+$'";
NOT REGEXP instead of !=1. To allow + at the start optionally, use ^\\+?. Since + is
a special character in regular expressions, it must be escaped with a
backslash (which must be escaped with another backslash). You then need
one or more digits ([0-9]+), up to the end of the string $.$query="UPDATE table SET phone='NULL' WHERE phone NOT REGEXP '^\+?[0-9]+$'";
This will match anything that doesn't begin optionally with
'^\\+?[0-9.-]+$' +, followed by digits only. If you also need to permit hyphens and dots in the phone number, add them into the [] character class:
Comments
Post a Comment