Reputation: 67
I'm trying to preg_match numbers which can be in any of these formats:
1) 81113333 or 91113333 (8-digit without any space in between. must start with 8 or 9)
2) 8111 3333 or 9111 3333 (8-digit with a space in between. must start with 8 or 9)
3) 8111-3333 or 9111-3333 (8-digit with a hyphen in between. must start with 8 or 9)
Upvotes: 1
Views: 744
Reputation:
If you're looking to validate such a number, use the expression below. You may have to modify it a bit (remove the start and end of string anchors) if you're looking to match sub-strings matching the pattern.
/^[89]\d{3}[ -]?\d{4}$/
Upvotes: 2