Number validation issue

Discussion in 'Python' started by Morten Engvoldsen, Feb 22, 2013.

  1. Hi ,
    I have wrote the below code to validate a number using modulus 10 and 11:

    def is_valid_number(checknum, mod):
    if mod == 10:
    if not len(checknum) >= 2 and len(checknum) <=25:
    return False
    number = tuple(int(i) for i in reversed(str(checknum)) )
    return (sum(int(num) * 2 for num in number[1::2]) % 10) == 0
    elif mod == 11:
    if not len(checknum)!= 11:
    return False
    weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]
    return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) ==
    0

    is_valid_number("12345678217", 10)

    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
    ..............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this format.

    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.

    Regards,
    Morten
     
    Morten Engvoldsen, Feb 22, 2013
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,890
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,743
  3. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    606
    Tommy
    Nov 29, 2003
  4. Matt
    Replies:
    14
    Views:
    4,546
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  5. Lucas Tam
    Replies:
    2
    Views:
    1,316
    Lucas Tam
    Feb 26, 2004
  6. =?Utf-8?B?ZGh1cndpdHo=?=
    Replies:
    1
    Views:
    642
    Teemu Keiski
    Apr 10, 2004
  7. =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=

    Using Summary Validation control with server Custom validation

    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=, Oct 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,074
    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=
    Oct 15, 2004
  8. =?Utf-8?B?dmlkeWE=?=
    Replies:
    1
    Views:
    956
    Kevin Spencer
    Jun 2, 2005
Loading...