I created a new content type called "phone numbers", then added a phone number field. Went to the create content page and selected "phone numbers", entered in the value 12051231234, and saved the page. When viewing the page the phone number shows as "1 --".

I tried various values for the number including "1-205-123-1234" and "205-123-1234" but I get the same output.

This is on a new drupal 5.2 install. I upgraded to 5.3 but same problem. Uninstalled then reinstalled the module also just to see.

Anybody know what the deal is?

Thanks,

Tim

CommentFileSizeAuthor
#3 phone_187224_ca_prefix_val.patch714 bytesdboulet

Comments

dboulet’s picture

Version: 5.x-1.5 » 5.x-2.11
Priority: Normal » Critical

I'm having the same problem with version 2.11. The Phone field works fine in 2 of my CCK nodetypes, but not in a third. For that particular nodetype, the phone numbers are saved in the database as "()-". For some reason the numbers are being stripped out.

dboulet’s picture

Priority: Critical » Normal

It turns out that the problem was not with the content type, but with the number that I was entering. I was entering the number as '204-123-4567'.

The problem is that this number still validates, but does not work with the regex match in phone.ca.inc. The regex does not recognize a prefix that starts with a 1, and therefore $matches remains empty after preg_match() on line 57. That's why the phone number is saved as blank in the database.

A solution would be to change the form validation so that, if a value is entered with a prefix that starts with '1', it produces an error. Line 22 of phone.ca.inc would be changed from:

    \d{3}         # 3-digit prefix

to:

    [02-9]\d{2}   # 3-digit prefix (can't start with 1)
dboulet’s picture

Title: Can't get the phone number to save in my content type » Phone number is not saved if prefix starts with 1
Version: 5.x-2.11 » 6.x-2.7
Component: Miscellaneous » Code
Status: Active » Needs review
StatusFileSize
new714 bytes

Here's a patch that fixes the validation for Canadian phone numbers, prefixes that start with the number 1 should not be allowed.

thierry_gd’s picture

Status: Needs review » Fixed

Taken into account in 6.2.8 release

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.