6

In an application i need to validate a form field for german telephone numbers,tried some but doesnt works exactly, any help will be appreciated..

Shanib
  • 155
  • 1
  • 3
  • 13
  • What does a German telephone number look like? – ATOzTOA Jan 10 '13 at 09:02
  • is the number comprehensive of the +(intl prefix) ? – BigMike Jan 10 '13 at 09:02
  • i guess you want to check if the area code exists? or what exactly do you want to check? Just my opinion: dont do it anyway, or have you ever seen ANY form that actually checks if a telephone number is correct / plausible? – x4rf41 Jan 10 '13 at 09:04
  • is the number check is enough for a telephone number field? – Shanib Jan 10 '13 at 09:12
  • 1
    I think this is the format? 1. " nnn - nnn nn nn " in case of Big Cities. 2. " nnnn - nn nn nn " in case of Small Towns. For Zwolle (Big Cities) : 038 - 123 45 67 For xyzTown(Small Cities/Town) : 0381 - 12 34 56 – Edd Jan 10 '13 at 09:13
  • Checking if an areacode exists is not really possible. The following telephone numbers are all valid an equal: "+49 (0)371 111222" "+49 371 111222" "0371 111222" "0371111222" "(0371) 111222". There are more combinations possible. – some_coder Jan 10 '13 at 09:42

1 Answers1

10

The answers to this question should solve this for you: Validate phone number with JavaScript

You just need to adjust the regex to suit the German format

The regex from https://github.com/posabsolute/jQuery-Validation-Engine/issues/265 might do the job: /^([+][0-9]{1,3}[ .-])?([(]{1}[0-9]{1,6}[)])?([0-9 .-/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/

Community
  • 1
  • 1
Edd
  • 8,402
  • 14
  • 47
  • 73
  • 7
    slightly adapted version resolving some minor issues with country code detection in combination with the actual number: `^(?:([+][0-9]{1,2})+[ .-]*)?([(]{1}[0-9]{1,6}[)])?([0-9 .-/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$` – 0x8BADF00D Jan 13 '15 at 20:40