By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,346 Members | 2,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,346 IT Pros & Developers. It's quick & easy.

Phone Number vallidation for German phone number.

P: 11
i want below numbers only should be validate.
0891234567
089-1234567
+49(89)123456
0049-89-123456
089 123456-78

Thanks in advance.
Jun 24 '16 #1
Share this Question
Share on Google+
19 Replies


Dormilich
Expert Mod 5K+
P: 8,639
what have you tried?
Jun 26 '16 #2

P: 11
i tried this below expression.
Expand|Select|Wrap|Line Numbers
  1. ^((?:\+\d+)?\s*(?:\(\d+\)\s*(?:[\/–-]\s*)?)?\d+(?:\s*(?:[\s\/–-]\s*)?\d+)*)$
this expression is allowed uk phone numbers.It should not allowed uk phone numbers.
PFB UK phone numbers.
01611234567
0161 123 4567
(0161) 123 4567
0161-123-4567
+44 161 123 4567
+441611234567
+44(0)161234567
00 44 161 1234567
(011) 44 161 234567
0161-158-5587
Jun 27 '16 #3

Dormilich
Expert Mod 5K+
P: 8,639
this expression is allowed uk phone numbers.
that's because there is no restriction regarding the country code. you would have to replace +\d+ by +49 (at least)
Jun 27 '16 #4

P: 11
is there any other format phone numbers other than below numbers for germany. If have send me the format numbers and regex.

0891234567
089-1234567
+49(89)123456
0049-89-123456
089 123456-78

Thanks.
Jun 27 '16 #5

P: 11
I have tried below regular expression still some uk formats still executing.

Expand|Select|Wrap|Line Numbers
  1. ^((?:\+49|\+89)?\s*(?:\(([89|49])+\)\s*(?:[\/–-]\s*)?)?\d+(?:\s*(?:[\s\/–-]\s*)?\d+)*)$
.

below UK format numbers still executing.
00 44 161 1234567
0161-123-4567
0161 123 4567

for eg : 0161 123 4567 this format starting has 4 digits but for DE site has 3 digits. how to handle this scenario.

Thanks in advance.:)
Jun 27 '16 #6

Dormilich
Expert Mod 5K+
P: 8,639
this expression is allowed uk phone numbers.
the only reliable phone format is the sequence of digits used to make a call, additionally using + to denote the call prefix (usually 00, but this may depend on the phone system used).

if you're calling within Germany, you simply replace the country code by the trunk code (0).

any other formatting (spaces, brackets, etc.) is nothing more than a visual aid to better remember the phone number and has no effect on the the functionality.

this essentially boils down to: (((\+|00+)49)|0)[1-9]\d+
Jun 27 '16 #7

Dormilich
Expert Mod 5K+
P: 8,639
below UK format numbers still executing.
that's because you have made the country code optional.
Jun 27 '16 #8

P: 11
Thanks Dormilich :).

can you tell where i have to place this expression "(((+|0{2,})49)|0)[1-9]\d+" in to this expression "^((?:\+49|\+89)?\s*(?:\(([89|49])+\)\s*(?:[\/–-]\s*)?)?\d+(?:\s*(?:[\s\/–-]\s*)?\d+)*)$".

Thanks in Advance :).
Jun 27 '16 #9

Dormilich
Expert Mod 5K+
P: 8,639
nowhere. that would be a total replacement.
Jun 27 '16 #10

P: 11
this expression((((+|0{2,})49)|0)[1-9]\d+) i s showing error in https://regex101.com/#javascript site.Please look into it.

Thanks.
Jun 27 '16 #11

Dormilich
Expert Mod 5K+
P: 8,639
See fix at #7
Jun 27 '16 #12

P: 11
i am not getting please send me perfect regex.
Jun 28 '16 #13

P: 11
i have to restrict below format numbers for german phone number with the following regex.
Regex : ^((?:\+49|\+89)?\s*(?:\(([89|49])+\)\s*(?:[\/–-]\s*)?)?\d+(?:\s*(?:[\s\/–-]\s*)?\d+)*)$

Numbers : 00 44 161 1234567,0161-123-4567,0161 123 4567
Jun 28 '16 #14

Dormilich
Expert Mod 5K+
P: 8,639
it's not going to work with this RegExp as long as the country code is optional.
Jun 28 '16 #15

P: 11
i have to restrict at-least this number.
00 44 161 1234567
Jun 28 '16 #16

Dormilich
Expert Mod 5K+
P: 8,639
with a bit of preparation, my RegExp works.
Jun 28 '16 #17

P: 11
i am using this regex(^((?:\+49|\+89)?\s*(?:\(([89|49])\d+\)\s*(?:[\/–-]\s*)?)?\d+(?:\s*(?:[\s\/–-]\s*)(?!44{1,2})\d+)*)$) it is working fine but i have one query.

suppose if the number does not allow using this regex(?!44) .If we allow the number what we have to use.
Jun 28 '16 #18

Dormilich
Expert Mod 5K+
P: 8,639
youre making it unnecessarily complicated with this RegExp. there is no need to regard spaces, parentheses, hyphens, dots, and whatnot in a number validation.

the RegExp I posted in #7 is sufficient.
Jun 28 '16 #19

P: 11
Thanks Dormilich, for supporting and much appreciated. if the number having like 00 44 161 1234567.this number has 00 44 has uk code right, this one i have to restrict.
Jun 28 '16 #20

Post your reply

Sign in to post your reply or Sign up for a free account.