Skip to content

Commit

Permalink
Evita que valide subcadenas dentro del valor dado
Browse files Browse the repository at this point in the history
Añadidos ^ y $ a las expresiones regulares para garantizar que toda la cadena es válida.
  • Loading branch information
leio10 committed Feb 4, 2015
1 parent 1c86c6d commit fe90c48
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 fe90c48

Please sign in to comment.