Posted By

Activetuts on 01/04/11


Tagged

regexp validation as3 iban


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

chus
elderhsouza


Validate IBAN with RegExp


 / Published in: ActionScript 3
 

URL: http://active.tutsplus.com/tutorials/actionscript/validating-various-input-data-in-flash/

From the tutorial, Validating Various Input Data in Flash (http://active.tutsplus.com/tutorials/actionscript/validating-various-input-data-in-flash/)

  1. public function validateIBAN(iban:String):Boolean
  2. {
  3. var nums:Object = { A:10, B:11, C:12, D:13, E:14,
  4. F:15, G:16, H:17, I:18, J:19,
  5. K:20, L:21, M:22, N:23, O:24,
  6. P:25, Q:26, R:27, S:28, T:29,
  7. U:30, V:31, W:32, X:33, Y:34, Z:35 };
  8. var chars:Array = iban.split('');
  9.  
  10. for (var i:int = 0; i < 4; i++)
  11. {
  12. chars.push(chars.shift());
  13. }
  14.  
  15. var exp:RegExp = /[a-z]/i;
  16. for (var j:int = 0; j < chars.length; j++)
  17. {
  18. chars[j] = exp.test(chars[j]) ? nums[chars[j].toUpperCase()] : chars[j];
  19. }
  20. iban = chars.join('');
  21. return modulus(iban, 97) == 1;
  22. }
  23.  
  24. public function modulus(largeNumber:String, mod:uint):Number
  25. {
  26. var tmp:String = largeNumber.substr(0, 10);
  27. var number:String = largeNumber.substr(tmp.length);
  28. var result:String;
  29.  
  30. do {
  31. result = String(Number(tmp) % mod);
  32. number = result + number;
  33. tmp = number.substr(0, 10);
  34. number = number.substr(tmp.length);
  35.  
  36. } while (number.length > 0);
  37.  
  38. return Number(tmp) % mod;
  39. }

Report this snippet  

You need to login to post a comment.