Ruby Code validation

  • Profile Image
    Asked on August 09, 2016 at 09:15 AM

    Hi guys,


    I have a question wrt verification of a number field (13 digits) with this Ruby code:

    def validjmbg jmbg len = jmbg.scan(/[0-9]/).size valid_chars = (jmbg =~ /^[0-9]+$/) if len!=13 or !valid_chars return false else j = jmbg.split(//).map(&:to_i) v = 11-((7*(j[0]+j[6])+ 6*(j[1]+j[7])+ 5*(j[2]+j[8])+ 4*(j[3]+j[9])+ 3*(j[4]+j[10])+ 2*(j[5]+j[11]))%11) v = 0 if v>9 return v==j[12] end end

    Is it doable?


    This is a formula that I've got for validating Unique Citizen Number. 



  • Profile Image
    Answered on August 09, 2016 at 11:00 AM

    Regarding the Ruby code, it looks fine, the length is 13, it should be numbers and then, I guess it is some kind of formula to give you the unique 13 digits number.

    Now, this should be doable, but you will have to download the whole source code of your form and do some coding to apply that to a certain field.

    I'm not sure how good are you in coding, but it should be doable.

    If you have further questions please let us know.

    Thank you!