There are two types of phone number in Philippines.
First Type = it start with 09 followed by 9 numbers. I already did this. This is my pattern for this.
^(09)\\d{9}
and it is working.
Second Type = it start with +639 followed by 9 numbers. Example is +6391571825. I can't identify the pattern for this because it has special character. What is the pattern for this?
Just escape the special character and place it in alternation as
^(09|\+639)\d{9}$
(09|\+639) Alternation matches either 09 or +639
$ Anchors the regex at the end of the string. This ensures that no more digits can appear after the 9 characters.
Regex Demo
I use this regex: ((^(\+)(\d){12}$)|(^\d{11}$))
It matches either of the following formats 1. +639191234567, or 2. 09191234567
Explanation
There are 2 chunks combined in 1 expression. Note that you can hardcode "63" in the expression and change the first chunk like so (^(\+63)(\d){10}$)
(^(\+)(\d){12}$) matches the mobile number with area code i.e. +63927...^(\+) - starts with a +(\d){12}$ - ends with any digit of length 12(^\d{11}$)) matches the number without the area code i.e. 0917...\+ - '+' literal \d - matches a digit from 0 - 9{12} - matches the length 12 ^ - starts with$ - ends withI test my regex here: regex101.com
Happy coding! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With