If you use an international phone field, (don't know about just dutch) and put in a dutch phone number with country prefix, validation fails.

Patch attached

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

g1smd’s picture

The code is inefficient.

For example, [0]{1}[6]{1} simplies to 06.

A character group is not needed.

# Phonenumber with 4 digit area code
- ([0]{1}[1-9]{1}[0-9]{2}[-\s]+[1-9]{1}[\s]*([0-9]{1}[\s]*){5})
+ ((?:\+31[ ]?|[0]{1}){1}[1-9]{1}[0-9]{2}[-\s]*[1-9]{1}[\s]*([0-9]{1}[\s]*){5})

All of the {1} counts can be removed; one is the default.
The [ ]? simplifies to \s?
Single character or digit in a group doesn't need to be in a group, e.g. [0] should be 0 and [\s] should be \s.

roderik’s picture

Issue summary: View changes
FileSize
4.8 KB
4.32 KB

That patch did not properly match (bracket) things. It probably didn't spot that the pairs of two regexes it deleted from the original code, are slightly different.

It also didn't spot phone numbers that are too long, but just truncated them.

Here's an updated patch. It also matches bracketed area codes, like (010) 1234567. In order to support that, I had to pull the regex apart into 3 pieces, otherwise I got extra empty matches (I don't know why).

This is now the official notation (See the 2nd table on https://nl.wikipedia.org/wiki/Telefoonnummer) - but I did not dare to change the output, because maybe existing users of the module will not expect that. So the output is still 010-1234567.

roderik’s picture

Version: 6.x-2.18 » 7.x-1.x-dev
FileSize
4.89 KB
1.99 KB

The regex didn't match the dash in '+31-' yet, even though that's what the code outputs. Fixing.

BarisW’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies cleanly and fixes all issues I had with the phone field. Great work Roderik!

idebr’s picture

Thanks Roderik, #3++

absoludo’s picture

Patch still applies cleanly.
Can it be scheduled for the next release?