Hi ,<br>I have wrote the below code to validate a number using modulus 10 and 11:<br><br>def is_valid_number(checknum, mod):<br> if mod == 10:<br> if not len(checknum) >= 2 and len(checknum) <=25:<br> return False<br>
number = tuple(int(i) for i in reversed(str(checknum)) )<br> return (sum(int(num) * 2 for num in number[1::2]) % 10) == 0<br> elif mod == 11:<br> if not len(checknum)!= 11:<br> return False<br>
weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]<br> return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) == 0<br><br>is_valid_number("12345678217", 10)<br><br>The above code is able to validate 25 length number for modulus 10 , but for modulus 11 i have done the validation only for 11 digit, Since for modulus 11 the weight should be in <br>
.............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this format. <br><br>Could you please let me know how can i validate the 25 length number for modulus 11 with weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this format.<br>
<br>Regards,<br>Morten <br><br><br>