Advertisement
atanasovetr

Untitled

May 30th, 2021
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function is_valid_egn(id){
  2.    var idRGEX = /^[0-9]{10}$/;
  3.    if(!idRGEX.test(id)){
  4.     return false;
  5.    }
  6.     var val = id[0]*2 + id[1]*4 + id[2]*8 + id[3]*5 + id[4]*10 + id[5]*9 + id[6]*7 + id[7]*3 + id[8]*6;
  7.     val = (val % 11) % 10;
  8.     return val == id[9];
  9. }
  10.  
  11. function alertValidIBAN(iban) {
  12.     if(isValidIBANNumber(iban) == 1){
  13.       return true;
  14.     }
  15.     return false;
  16. }
  17.  
  18. function isValidIBANNumber(input) {
  19.     var CODE_LENGTHS = {
  20.         AD: 24, AE: 23, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BR: 29,
  21.         CH: 21, CR: 21, CY: 28, CZ: 24, DE: 22, DK: 18, DO: 28, EE: 20, ES: 24,
  22.         FI: 18, FO: 18, FR: 27, GB: 22, GI: 23, GL: 18, GR: 27, GT: 28, HR: 21,
  23.         HU: 28, IE: 22, IL: 23, IS: 26, IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28,
  24.         LI: 21, LT: 20, LU: 20, LV: 21, MC: 27, MD: 24, ME: 22, MK: 19, MR: 27,
  25.         MT: 31, MU: 30, NL: 18, NO: 15, PK: 24, PL: 28, PS: 29, PT: 25, QA: 29,
  26.         RO: 24, RS: 22, SA: 24, SE: 24, SI: 19, SK: 24, SM: 27, TN: 24, TR: 26,  
  27.         AL: 28, BY: 28, CR: 22, EG: 29, GE: 22, IQ: 23, LC: 32, SC: 31, ST: 25,
  28.         SV: 28, TL: 23, UA: 29, VA: 22, VG: 24, XK: 20
  29.     };
  30.     var iban = String(input).toUpperCase().replace(/[^A-Z0-9]/g, ''), // keep only alphanumeric characters
  31.             code = iban.match(/^([A-Z]{2})(\d{2})([A-Z\d]+)$/), // match and capture (1) the country code, (2) the check digits, and (3) the rest
  32.             digits;
  33.     // check syntax and length
  34.     if (!code || iban.length !== CODE_LENGTHS[code[1]]) {
  35.         return false;
  36.     }
  37.     // rearrange country code and check digits, and convert chars to ints
  38.     digits = (code[3] + code[1] + code[2]).replace(/[A-Z]/g, function (letter) {
  39.         return letter.charCodeAt(0) - 55;
  40.     });
  41.     // final check
  42.     return mod97(digits);
  43. }
  44.  
  45. function mod97(string) {
  46.     var checksum = string.slice(0, 2), fragment;
  47.     for (var offset = 2; offset < string.length; offset += 7) {
  48.         fragment = String(checksum) + string.substring(offset, offset + 7);
  49.         checksum = parseInt(fragment, 10) % 97;
  50.     }
  51.     return checksum;
  52. }
  53.  
  54.  
  55. function validate(){
  56.   var username = document.getElementById('username').value;
  57.   var pass = document.getElementById('pass').value;
  58.   var confpass = document.getElementById('confpass').value;
  59.   var id = document.getElementById('id').value;
  60.   var iban = document.getElementById('iban').value;
  61.   var birth = document.getElementById('birth').value;
  62.   var email = document.getElementById('email').value;
  63.   var num = document.getElementById('num').value;
  64.   // alert(is_valid_egn(id));
  65.  
  66.   var usernameRGEX = /^[a-zA-Z0-9_]{5,}$/;
  67.   var passRGEX = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#-_])[A-Za-z\d@$!%*?&#-_]{8,}$/;
  68.   var idRGEX = /^\d{10}$/;
  69.   var birthRGEX = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/m;
  70.   var emailRGEX = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
  71.   var numRGEX = /(([+][(]?[0-9]{1,3}[)]?)|([(]?[0-9]{4}[)]?))\s*[)]?[-\s\.]?[(]?[0-9]{1,3}[)]?([-\s\.]?[0-9]{3})([-\s\.]?[0-9]{2,4})/;
  72.  
  73.   var usernameResult = usernameRGEX.test(username);
  74.   var passResult = passRGEX.test(pass);
  75.   var confpassResult = pass == confpass;
  76.   var idResult = is_valid_egn(id);
  77.   var ibanResult = alertValidIBAN(iban);
  78.   var birthResult = birthRGEX.test(birth);
  79.   var emailResult = emailRGEX.test(email);
  80.   var numResult = numRGEX.test(num);
  81.  
  82.  
  83.  
  84.   alert("username: " + usernameResult +
  85.       "\npassword: "+ passResult +
  86.       "\nconfirm pass: " + confpassResult +
  87.       "\nid: " + idResult +
  88.       "\niban: " + ibanResult +
  89.       "\nbirthdate: " + birthResult +
  90.       "\nemail: " + emailResult +
  91.       "\nnum: " + numResult);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement