The Singaporean phone number format starts with either a 8,6 or 9, and is followed by 7 digits. I tried this regex, but it does not work. Where did I go wrong?
Code: Select all
preg_match('/'^[9|6|8]\d{7,7}$'/i', '91111111 ', $result);Moderator: General Moderators
Code: Select all
preg_match('/'^[9|6|8]\d{7,7}$'/i', '91111111 ', $result);Code: Select all
preg_match('/^[689]\d{7}$/D', '91111111', $result);FYI, character classes always match one character and the "normal" regex meta characters don't apply inside them, so your: [9|6|8] matches either a '9', a '6', a '8' or a '|' (!), since the pipe-char has no meaning inside it.LonelyProgrammer wrote:Thanks...it was originally a non-PERL compatible regex and I tried to convert it to one. Looks like I have done a clumsy job at that.
The first one is also faster.prometheuzz wrote:Note that [968] is the same as (9|6|8), although when matching only one character, the first is preferred by many.
Albeit barely noticeable in this case.GeertDD wrote:The first one is also faster.prometheuzz wrote:Note that [968] is the same as (9|6|8), although when matching only one character, the first is preferred by many.