You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some spanish company CIF generated are invalid. For example: N6043409
spanish_cif_control_digit is missing
To Reproduce
Faker::Company.spanish_organisation_number
Expected behavior
LETTERS_CIF=%w[ABCDEFGHJNPQRSUVW]LETTERS_CIF_NUMBER=%w[PQSW]LETTERS_CIF_CONTROL=%w[JABCDEFGHI]REGEX_CIF=/^(#{LETTERS_CIF.join('|')})\-?(\d{7})\-?(\d|#{LETTERS_CIF_CONTROL.join('|')})$/`N6043409` =~ REGEX_CIF# invalid CIF generated by faker=>nil'U59881409' =~ REGEX_CIF# valid CIF generated by faker=>0
Additional context
Example of validation method:
defcif_valid?(cif)ifcif =~ REGEX_CIFnumber=Regexp.last_match(2)first_letter=Regexp.last_match(1)province_code=number[0..1]actual_control=Regexp.last_match(3)total=number.split('').each_with_index.inject(0)do |acc,(element,index)|
acc + ifindex.even?(element.to_i * 2).digits.inject(:+)elseelement.to_iendenddecimal=total.digits.firstexpected_control=decimal != 0 ? 10 - decimal : decimal# Control code must be a letterreturnLETTERS_CIF_CONTROL[expected_control]ifLETTERS_CIF_NUMBER.include?(first_letter) ||
province_code == '00'# Control code will be a number or a letterreturn[expected_control.to_s,LETTERS_CIF_CONTROL[expected_control]].include?(actual_control)endfalseend
The text was updated successfully, but these errors were encountered:
Describe the bug
Some spanish company CIF generated are invalid. For example:
N6043409
spanish_cif_control_digit
is missingTo Reproduce
Faker::Company.spanish_organisation_number
Expected behavior
Additional context
Example of validation method:
The text was updated successfully, but these errors were encountered: