Reputation: 1099
these are some of indonesia phone number
08xxxxxxxxx (Consist of minimal 11 char length)
08xxxxxxxxxxx (always started with 08)
i found this one is useful
Regex regex = new Regex(@"08[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
but, it only support for 12 character, if i change them into the following regex
Regex regex = new Regex(@"08[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
it only support for 11 character, how do i make regex for validating to begins with 08
and minimal length is 11?
Upvotes: 2
Views: 7489
Reputation: 1
((\+62 8\d{2}([ -])|08\d{2}([ -]?)|\+628\d{2})\d{4}(\3\4)\d{2,5})
this will accept most used style like
08xx xxxx xxxx
08xxxxxxxxxxxx
08xx-xxxx-xxxx
+628xxxxxxxxxx
+62 8xx xxxx xxxx
+62 8xx-xxxx-xxxx
also this will check for 11-13 long numbers
sorry for the grammar though
Upvotes: 0
Reputation: 11
I'd add more complete version, here they are (with digit grouping)
([\[\(])?(?:(\+62)|62|0)\1? ?-? ?8(?!0|4|6)\d(?!0)\d\1? ?-? ?\d{3,4} ?-? ?\d{3,5}(?: ?-? ?\d{3})?\b
It will accept format such
(0811) 123 123
[62] 812 1234567
0812 345 6789
+62856123456789
0878-123-123-123
[+62823] 1234 - 56789
---> I believe this is the longest phone number as the time of writing
Upvotes: 1
Reputation: 191749
^08[0-9]{9,}$
The {9,}
means "at least 9," but possibly more.
I changed it to 9 to account for the two leading digits (which would add up to 11).
Upvotes: 6
Reputation: 2007
08\d{9,10}
Translates to "begins with 08"; Minimum 11 maximum, 12 digits long.
edit: count.
Upvotes: 4
Reputation: 263723
how about this pattern?
^08\d{9,10}$
this will check for 11 to 12 characters including 08
Upvotes: 1