aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers
diff options
context:
space:
mode:
authorrpheath <rpheath@gmail.com>2009-03-08 23:52:28 -0400
committerPratik Naik <pratiknaik@gmail.com>2009-03-09 12:53:44 +0000
commit1ab2ff58eddee8ac523624dd097424f9a760ad8b (patch)
tree0e23cec568020d67ba739f1dc900b2865b0b8067 /actionpack/lib/action_view/helpers
parentfaf4ba6b79e56dde383a8761fb1f485fcd07c72b (diff)
downloadrails-1ab2ff58eddee8ac523624dd097424f9a760ad8b.tar.gz
rails-1ab2ff58eddee8ac523624dd097424f9a760ad8b.tar.bz2
rails-1ab2ff58eddee8ac523624dd097424f9a760ad8b.zip
Fixed number_to_phone to work with 7 digit numbers [#2176 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r--actionpack/lib/action_view/helpers/number_helper.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb
index e622f97b9e..539f43c6e3 100644
--- a/actionpack/lib/action_view/helpers/number_helper.rb
+++ b/actionpack/lib/action_view/helpers/number_helper.rb
@@ -15,6 +15,7 @@ module ActionView
# * <tt>:country_code</tt> - Sets the country code for the phone number.
#
# ==== Examples
+ # number_to_phone(5551234) # => 555-1234
# number_to_phone(1235551234) # => 123-555-1234
# number_to_phone(1235551234, :area_code => true) # => (123) 555-1234
# number_to_phone(1235551234, :delimiter => " ") # => 123 555 1234
@@ -37,7 +38,8 @@ module ActionView
str << if area_code
number.gsub!(/([0-9]{1,3})([0-9]{3})([0-9]{4}$)/,"(\\1) \\2#{delimiter}\\3")
else
- number.gsub!(/([0-9]{1,3})([0-9]{3})([0-9]{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3")
+ number.gsub!(/([0-9]{0,3})([0-9]{3})([0-9]{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3")
+ number.starts_with?('-') ? number.slice!(1..-1) : number
end
str << " x #{extension}" unless extension.blank?
str