What will be the Javascript or JQuery code for following scenario ?

"A ABA TextBox=Mandatory field".

Must be numeric and 9 digits. Perform MOD 10 algorithm

  1. Multiply each digit of the first 8 digits of the ABA/Routing number with the following numbers respectively. a. 3,7,1,3,7,1,3,7
  2. Add the results of the 8 multiplications.
  3. Subtract the sum from the next highest multiple of 10.
  4. The result of the above step 3 must be equal to the 9th digit of the ABA/Routing number. If not display error in Message section

I have 9 different textboxes for each digit of ABA number . First I have to check if the entered number is numeric or not then I have to add this valid number in a String Array onwhich finally i will be adding my ABA Number validation .

I am absolutely stuck . Dont know how to solve this thing . I have found few codes but which doesnt qualify my need

EDIT :This is my HTML Code OnKeyUp Event I am adding value of perticular textbox in a string Array and OnKeyPress I am checking if the entered number is numeric or not

    <div style="padding-bottom: 5px; padding-left: 200px;padding-right: 20px;padding-top: 0;vertical-align: middle; width: 500px;">
  <input type="text" maxlength="1" size="10px" style="width:15px" id="ab1" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();"  /> 
  <input type="text" maxlength="1" size="10px" style="width:15px" id="ab2" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();" />
  <input type="text" maxlength="1" size="10px" style="width:15px" id="ab3" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();" /> 
  <input type="text" maxlength="1" size="10px" style="width:15px" id="ab4" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();" /> 
  <input type="text" maxlength="1" size="10px" style="width:15px" id="ab5" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();"  />
  <input type="text" maxlength="1" size="10px" style="width:15px" id="ab6" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();" />
  <input type="text" maxlength="1"  size="10px" style="width:15px" id="ab7" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();" /> 
  <input type="text" maxlength="1" size="10px" style="width:15px" id="ab8" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();" /> 
  <input type="text" maxlength="1" size="10px" style="width:15px" id="ab9" onkeypress ="return onlyNumbers();" onkeyup ="return addABNumbers();" /> 
  <input type="hidden" id="finalABNumber" value=""  onkeyup="return onlyNumbers();" />
  </div>

  <script language="javascript" type="text/javascript">
    function addABNumbers() {
        var finalabNumber = document.getElementById("ab1").value + document.getElementById("ab2").value +
                                                     document.getElementById("ab3").value +
                                                     document.getElementById("ab4").value +
                                                     document.getElementById("ab5").value +
                                                    document.getElementById("ab6").value +
                                                    document.getElementById("ab7").value +
                                                    document.getElementById("ab8").value +
                                                    document.getElementById("ab9").value;

        alert(finalabNumber);
        document.getElementById('finalABNumber').value = finalabNumber;
    } function onlyNumbers() {
      //  debugger;
        var chek=true;
        //var finalNumber = document.getElementById('finalAcntNumber').value;
        //document.getElementById("finalAcntNumber").value =
        var finalNumber =
                                                     document.getElementById("ac1").value +
                                                     document.getElementById("ac2").value +
                                                     document.getElementById("ac3").value +
                                                     document.getElementById("ac4").value +
                                                     document.getElementById("ac5").value +
                                                    document.getElementById("ac6").value +
                                                    document.getElementById("ac7").value +
                                                    document.getElementById("ac8").value +
                                                    document.getElementById("ac9").value +
                                                    document.getElementById("ac10").value +
                                                    document.getElementById("ac11").value +
                                                    document.getElementById("ac12").value +
                                                    document.getElementById("ac13").value +
                                                    document.getElementById("ac14").value +
                                                    document.getElementById("ac15").value+
                                                    document.getElementById("ac16").value;
       // debugger;            
        var test = document.getElementById("ac1").value;

       // chek = IsNumeric(document.getElementById("ac1").value);
       //            alert(chek);
       //            if (finalNumber.length < 15 )
       //            if(chek=false)
       //                alert('not a valid');
       //            alert(finalNumber);
        var e = event || evt; // for trans-browser compatibility
        var charCode = e.which || e.keyCode;

        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
        else if (isNaN(document.getElementById('finalAcntNumber').value)) {
            alert('not a valid');
        }
        else {
           // debugger;
        //                if (test != "") {
        //                    alert(finalNumber);
                document.getElementById("Text1").value = finalNumber;
          //  }
            return true;
        }
       //   if (!isNaN(document.getElementById("finalAcntNumber").value))


      }
    </script>
link|improve this question

77% accept rate
4  
Probably a good idea to accept some answers for past questions – Robert May 13 '11 at 13:09
1  
please show some of your code. is this homework? – Daniel A. White May 13 '11 at 13:24
1  
Where are you stuck? – Quentin May 13 '11 at 13:25
I am stuck with everything . – Ashes May 13 '11 at 13:43
1  
I have a box per digit as per my Use Case diagram and Requirement document . It is a must for me . In my OnlyNumbers function I am checking if entered number is numeric or not and in addABNumbers function I am adding different valid Box values in a Variable ABNumber which is then saved in a Hidden field – Ashes May 13 '11 at 13:58
show 1 more comment
feedback

2 Answers

I wouldn't split your input into 8 boxes; just use one. I know how to do this, but others will down-vote if I just outright answer your question, so I'll refrain from posting code.

However, you should look into the javascript isNan function; that will help you validate on numbers. The rest of the steps you listed are quite simple. What else are you stuck on?

link|improve this answer
1  
I am saving my 8 textbox values in a hidden field and from there on i am validating the same number . so u can ignore those textboxes but before that I have to compare this perticular number with another Renetered number so that user doesnt enter a wrong number . – Ashes May 16 '11 at 6:40
1  
I am saving my 8 textbox values in a hidden field and from there on i am validating the same number . so u can ignore those textboxes but before that I have to compare this perticular number with another Renetered number so that user doesnt enter a wrong number . ............... So the Sequense is going to be like this ... 1. User enters ABA number in 8 TextBoxes .( Allow Numeric only ).2. User Enters the same number in another 8 TBs(Numeric only) 3. Compare this number with earlier 8 TBs .3. Validate this Number(MOD 10 Algorithm and as per Requirement Doc Valid ABA number) ................... – Ashes May 16 '11 at 6:46
Need some Code :( – Ashes May 16 '11 at 6:48
feedback
up vote 1 down vote accepted

I figured out the answer on my own and the correct answer as per my requirement is as follows

<script>
function validation {
    var input = $("#someTextBox").val();

    if (!isNaN(input)) {
        var values = {
            input.charAt(0) * 3,
            input.charAt(1) * 7,
            input.charAt(2) * 1,
            input.charAt(3) * 3,
            input.charAt(4) * 7,
            input.charAt(5) * 1,
            input.charAt(6) * 3,
            input.charAt(7) * 7,
        }

        var sum = 0;

        for (int i = 0; i < values.length; i ++) {
            sum += values[i];
        }        

       var modTen = parseInt(sum / 10);
                    var result = (modTen + 1) * 10;

                    var finalResult = result - sum;
                    if (finalResult == (input.charAt(8)))
                        alert("Valid ABA Number.");
                    else
                        alert("Error");

}    
</script>
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.