Skip to content

Commit

Permalink
add alpha character and length check
Browse files Browse the repository at this point in the history
  • Loading branch information
garygreyling committed Sep 29, 2010
1 parent 202ace4 commit 904cdd6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'rubygems'
require 'rake'
require 'echoe'

Echoe.new('sa_vat_validation', '0.1.0') do |p|
Echoe.new('sa_vat_validation', '0.1.1') do |p|
p.description = "Validate South African VAT numbers easily"
p.url = "http://github.com/mpowered/sa_vat_validation"
p.author = "Gary Greyling"
Expand Down
7 changes: 7 additions & 0 deletions lib/sa_vat_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ def first_digit
end
end

class String
def is_numeric?
Float self rescue false
end
end

class SaVatValidation
def self.valid?(vat_number)
digits = vat_number.to_s.split(//).map(&:to_i)
return false unless digits.size == 10 && vat_number.to_s.is_numeric?
check_digit = digits.pop

sum = 0
Expand Down

0 comments on commit 904cdd6

Please sign in to comment.