Skip to content

Commit

Permalink
Merge pull request #4 from leio10/patch-1
Browse files Browse the repository at this point in the history
Evita que valide subcadenas dentro del valor dado
  • Loading branch information
javiertoledo committed Feb 5, 2015
2 parents 1c86c6d + fe90c48 commit ba9ecf0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/spanish_vat_validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def message(kind='vat')
def validate_nif(v)
return false if v.nil? || v.empty?
value = v.upcase
return false unless value.match(/[0-9]{8}[a-z]/i)
return false unless value.match(/^[0-9]{8}[a-z]$/i)
letters = "TRWAGMYFPDXBNJZSQVHLCKE"
check = value.slice!(value.length - 1..value.length - 1)
calculated_letter = letters[value.to_i % 23].chr
Expand All @@ -23,7 +23,7 @@ def validate_nif(v)
def validate_cif(v)
return false if v.nil? || v.empty?
value = v.clone
return false unless value.match(/[a-wyz][0-9]{7}[0-9a-z]/i)
return false unless value.match(/^[a-wyz][0-9]{7}[0-9a-z]$/i)
pares = 0
impares = 0
uletra = ["J", "A", "B", "C", "D", "E", "F", "G", "H", "I"]
Expand Down Expand Up @@ -57,7 +57,7 @@ def validate_cif(v)
def validate_nie(v)
return false if v.nil? || v.empty?
value = v.upcase
return false unless value.match(/[xyz][0-9]{7}[a-z]/i)
return false unless value.match(/^[xyz][0-9]{7}[a-z]$/i)
value[0] = {"X" => "0", "Y" => "1", "Z" => "2"}[value[0]]
validate_nif(value)
end
Expand Down

0 comments on commit ba9ecf0

Please sign in to comment.