Euro note code verifier required!

Discussion in 'Software' started by Rayzipan, Jun 9, 2008.

  1. Rayzipan

    Rayzipan Specialist

    Hi
    I use Euro as currency. I recently covered checksums in college. The various checksums covered Euro Note and Credit Card number verification methods. There are many sites to help someone verify that a credit card is authentic, however there seems to be no on line verification tool for Euro notes. It would be even better to have a JavaScript program that could do this, then you could check off line.

    This is how to verify a Euro note:
    Convert the first letter to a number.
    Then add up all the numbers and the letter which is now converted to a number.
    What ever the total is, the numbers must result in 8 in order for that Euro note to be authentic. (For example this note has a total of 71, then 7 + 1 = 8 therefore this is authentic.)

    Such a verification tool would be very useful for shop owners.

    If anyone is smart enough to make a JavaScript program to verify the validity of a Euro bank note, please post a link here.
    Or please post the code.

    I'd greatly appreciate it.

    Also one last thing, if someone could come up with JavaScript code to calculate this: http://en.wikipedia.org/wiki/PPS_number it would be wonderful.
     
  2. PC-XT

    PC-XT Master Sergeant

    I love making stuff like this when I have time. I'm not sure how to convert the letter to a number, but am assuming A=1, B=2, ..., Z=26

    Code:
    <script>
    function euroIsValid(num){
     t=num.substring(0,1).toUpperCase().charCodeAt();//charCodeAt() requires 4.0 browsers
     n=num.substring(1);
     while(n.length>1){
      for(i=0;i<n.length;i++)t+=parseInt(n.charAt(i));
      n=t;t=0;
     }
     return(parseInt(n)==8);
    }
    </script>
    Haven't had time to test this, might have errors, have to leave fast now...
     
  3. PC-XT

    PC-XT Master Sergeant

    Here is the corrected code, I don't know how long a Euro number is supposed to be, this accepts almost any length, but if you tell me, I can add a length verifier (at least a minimum length, I'll look it up myself if I have time l8r)
    Code:
    function euroIsValid(num){
     t=num.substring(0,1).toUpperCase().charCodeAt(0)-64;//charCodeAt() requires 4.0 browsers
     if(t<1||t>26)return false;//doesn't begin w/ letter
     n=num.substring(1);
     while(n.length>1){
      for(i=0;i<n.length;i++)if(isNaN(c=parseInt(n.charAt(i))))return false; else t+=c;
      n=t;t=0;
     }
     return(parseInt(n)==8);
    }
     
  4. Rayzipan

    Rayzipan Specialist


    Thank you very much PC-XT's. I will soon try out your code. Great work.
    ;)
     
  5. Rayzipan

    Rayzipan Specialist

    Yes, you are correct in saying A=1, B=2, Z=26, etc.

    I checked the reverse Euro note images here:
    http://en.wikipedia.org/wiki/Euro_banknotes

    I checked five different Euro banknotes and each one had 12 as their code length.

    Hope this helps.
     
  6. Rayzipan

    Rayzipan Specialist

    Hi,
    I tried the above code but nothing appears on the screen!
    Here is your code with the html:

    Code:
    <html>
    <head>
    </head>
    <body>
    
    <script>
    function euroIsValid(num){
     t=num.substring(0,1).toUpperCase().charCodeAt(0)-64;//charCodeAt() requires 4.0 browsers
     if(t<1||t>26)return false;//doesn't begin w/ letter
     n=num.substring(1);
     while(n.length>1){
      for(i=0;i<n.length;i++)if(isNaN(c=parseInt(n.charAt(i))))return false; else t+=c;
      n=t;t=0;
     }
     return(parseInt(n)==8);
    }
    </script>
    
    </body>
    </html>
    :confused
     
  7. PC-XT

    PC-XT Master Sergeant

    Sorry, it's meant to be used as a form validator. Here is a simple way to use it:

    Code:
    <html>
    <head>
    </head>
    <body>
    
    <script>
    function euroIsValid(num){
     if(num.length<12)return false;//added min length
     t=num.substring(0,1).toUpperCase().charCodeAt(0)-64;//charCodeAt() requires 4.0 browsers
     if(t<1||t>26)return false;//doesn't begin w/ letter
     n=num.substring(1);
     while(n.length>1){
      for(i=0;i<n.length;i++)if(isNaN(c=parseInt(n.charAt(i))))return false; else t+=c;
      n=t;t=0;
     }
     return(parseInt(n)==8);
    }
    
    //simple validation:
    document.write(
    euroIsValid(t=prompt("Please enter the Euro note's code number:/n(no spaces, please)",""))
    ?"The Euro note code number, "+t+", checks out ok.":t+" is a <font color=red size=5>Counterfeit Euro!</font>");
    </script>
    
    </body>
    </html>
     
  8. PC-XT

    PC-XT Master Sergeant

    Sorry again, that last post got messed up, and I took longer than 10 minutes to edit it, so it wouldn't let me, but here is better code: (added important var statement, tried to make code easier to understand by eliminating ternary operator, added notification of why the test fails)
    Code:
    <html>
    <head>
    </head>
    <body>
    
    <script>
    function euroIsValid(num){var t,n,i,c;
     if(num.length<12)return false;//added min length
     t=num.substring(0,1).toUpperCase().charCodeAt(0)-64;//charCodeAt() requires 4.0 browsers
     if(t<1||t>26)return false;//doesn't begin w/ letter
     n=num.substring(1);
     while(n.length>1){
      for(i=0;i<n.length;i++)if(isNaN(c=parseInt(n.charAt(i))))return false; else t+=c;
      n=t;t=0;
     }
     return(parseInt(n)==8);
    }
    
    //simple validation:
    t=prompt("Please enter the Euro note's code number:\n(no spaces, please)","");
    if(euroIsValid(t))document.write("The Euro note code number, "+t+", checks out ok.");
    else{
     document.write(t+" is a <font color=red size=5>Counterfeit Euro!</font>");
     if(t.length<12)document.write("<br>The code should be longer.");
     else document.write("<br>The checksum doesn't check out.");
    }
    </script>
    <p>Refresh this page to try another code.
    </body>
    </html>
     
  9. Rayzipan

    Rayzipan Specialist

    Thank you PC-XT, I will try it out and get back to you.
    Cheers buddy.

    :)
     
  10. Rayzipan

    Rayzipan Specialist

    Hi,
    I tried your code on two valid Euro code numbers yet both times the result stated they were counterfeit. You are nearly there however.

    Here are the two numbers I tried. As you can see the total of each of them adds to 8(when you add each digit of the total).

    X16787044667
    T15954373608
     
  11. PC-XT

    PC-XT Master Sergeant

    Sorry yet again... I forgot to add toString() to make sure that didn't happen:
    Code:
    <html>
    <head>
    </head>
    <body>
    
    <script>
    function euroIsValid(num){var t,n,i,c;
     if(num.length<12)return false;//added min length
     t=num.substring(0,1).toUpperCase().charCodeAt(0)-64;//charCodeAt() requires 4.0 browsers
     if(t<1||t>26)return false;//doesn't begin w/ letter
     n=num.substring(1);
     while(n.length>1){
      for(i=0;i<n.length;i++)if(isNaN(c=parseInt(n.charAt(i))))return false; else t+=c;
      n=t.toString();t=0;
     }
     return(parseInt(n)==8);
    }
    
    //simple validation:
    t=prompt("Please enter the Euro note's code number:\n(no spaces, please)","");
    if(euroIsValid(t))document.write("The Euro note code number, "+t+", checks out ok.");
    else{
     document.write(t+" is a <font color=red size=5>Counterfeit Euro!</font>");
     if(t.length<12)document.write("<br>The code should be longer.");
     else document.write("<br>The checksum doesn't check out.");
    }
    </script>
    <p>Refresh this page to try another code.
    </body>
    </html>
    That should work. I tested it with those numbers to make sure.
     
  12. PC-XT

    PC-XT Master Sergeant

    I'm working on the PPS verifier now. I'll test it better before I post it this time. :eek:
     
  13. Rayzipan

    Rayzipan Specialist

    Thank you PC-XT.
     
  14. PC-XT

    PC-XT Master Sergeant

    Here's the PPS verifier:
    Code:
    <html>
    <head>
    </head>
    <body>
    <script>
    function PPSisValid(num){var t=0,n,i,c;
     if(num.length<8)return false;
     n=num.charAt(7).toUpperCase().charCodeAt(0)-64;//charCodeAt() requires 4.0 browsers
     if(n<1||n>22)return false;//doesn't end w/ qualifying letter
     for(i=2;i<9;i++)if(isNaN(c=parseInt(num.charAt(8-i))))return false; else t+=c*i;
     return(t%23==n);
    }
    
    //simple validation:
    t=prompt("Please enter the PPS code number:\n(no spaces, please)","");
    if(t!==null){
     document.write("# "+t+":<p>")
     if(PPSisValid(t))document.write("That PPS code number is valid.");
     else{
      document.write("<font color=red size=5>Bad number!</font>");
      if(t.length<8)document.write("<br>The number is too short.");
      else document.write("<br>The checksum doesn't check out.");
    }}else document.write("User cancelled verification.");
    </script>
    <p>The PPS code should be 7 digits followed by a letter, and possibly extra letters, such as T, X, or for old ones, W. This doesn't check extra letters, as they are no longer used, or are special cases of use for the main number.
    <p>Refresh this page to try another code.
    </body>
    </html>
    I tested it on a few numbers. It should work. The only one it failed on was 8765432A, which I found on Wikipedia, but the valid letter for that seems to be S, so I think that was just an invalid example.
     
  15. PC-XT

    PC-XT Master Sergeant

    :eek: I found that the Euro verifier throws a small error if the user cancels, which isn't a big problem, but the following code displays a user cancellation message instead:
    Code:
    <html>
    <head>
    </head>
    <body>
    
    <script>
    function euroIsValid(num){var t,n,i,c;
     if(num.length<12)return false;//added min length
     t=num.substring(0,1).toUpperCase().charCodeAt(0)-64;//charCodeAt() requires 4.0 browsers
     if(t<1||t>26)return false;//doesn't begin w/ letter
     n=num.substring(1);
     while(n.length>1){
      for(i=0;i<n.length;i++)if(isNaN(c=parseInt(n.charAt(i))))return false; else t+=c;
      n=t.toString();t=0;
     }
     return(parseInt(n)==8);
    }
    
    //simple validation:
    t=prompt("Please enter the Euro note's code number:\n(no spaces, please)","");
    if(t!==null){
     if(euroIsValid(t))document.write("The Euro note code number, "+t+", checks out ok.");
     else{
      document.write(t+" is a <font color=red size=5>Counterfeit Euro!</font>");
      if(t.length<12)document.write("<br>The code should be longer.");
      else document.write("<br>The checksum doesn't check out.");
    }}else document.write("User cancelled verification.");
    </script>
    <p>Refresh this page to try another code.
    </body>
    </html>
    This wouldn't happen with a text form element's value, because it doesn't have any way to cancel, in case you wanted to use this function in form validation.
     
    Last edited: Jun 17, 2008
  16. Rayzipan

    Rayzipan Specialist

    Hi,
    I tried your latest code. It works on the two Euro note codes below.
    Excellent. You are a genius.

    :clap
     
  17. PC-XT

    PC-XT Master Sergeant

    Great. Thank you. I also posted the PPS number verifier code, if you want to try that as well.
     
  18. Rayzipan

    Rayzipan Specialist

    I tried both your codes. They are amazing. That is very clever thinking you did.
     
  19. PC-XT

    PC-XT Master Sergeant

    Thank you. I like to write JavaScript games and things. I had them on a website, but had trouble with users not being able to access the site, so I'm getting ready to get a new account. I'm thinking of just getting a temporary one, until I get the site better organized.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds