@deposits/validators
Version:
A collection of Fintech-specific and general-purpose validators, designed to extend popular validation libraries like Vuelidate, Zod, and yup.
2 lines (1 loc) • 1.9 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).DepositsValidators={})}(this,(function(t){"use strict";t.accountNumber=function(t){return!((t=t.trim()).length<4||t.length>17)&&/^[0-9]+$/.test(t)},t.creditCard=function(t){if(t=(t=t.trim()).replaceAll(" ",""),/^\d+$/.test(t)){for(var e=0,n=!1,r=t.length-1;r>=0;r--){var i=parseInt(t.charAt(r));n&&(i*=2)>9&&(i-=9),e+=i,n=!n}return e%10==0&&(!!/^3[47]\d{13}$/.test(t)||(!!/^4\d{12}(\d{3})?$/.test(t)||(!!/^5[1-5]\d{14}$/.test(t)||!!/^6(?:011|5\d{2})\d{12}$/.test(t))))}return!1},t.ein=function(t){t=t.trim();return/^\d{2}-\d{7}$/.test(t)},t.email=function(t){if(t.length>63)return!1;return/^[A-Za-z0-9]+(\.[A-Za-z0-9]+)*@[a-zA-Z]([a-zA-Z0-9\-]*[a-zA-Z0-9])*(\.[a-zA-Z]([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*\.([a-zA-Z]+)*$/.test(t)},t.itin=function(t){t=t.trim();return/^9\d{2}-\d{2}-\d{4}$/.test(t)},t.naics=function(t){t=t.trim();return!!/^\d{2,6}$/.test(t)&&!!{11:!0,21:!0,22:!0,23:!0,31:!0,32:!0,33:!0,41:!0,42:!0,44:!0,45:!0,48:!0,49:!0,51:!0,52:!0,53:!0,54:!0,55:!0,56:!0,61:!0,62:!0,71:!0,72:!0,81:!0,91:!0,92:!0}[parseInt(t.substring(0,2),10)]},t.name=function(t){if(t.length>40||t.length<2)return!1;return/^[a-zA-Z0-9'.&,\-\s]*$/.test(t)},t.oneWord=function(t){if(!t)return!1;return/^\S*$/.test(t)},t.passportNumber=function(t){t=t.trim();return/^[a-zA-Z0-9]{9}$/.test(t)},t.routingNumber=function(t){t=t.trim();if(!/^\d{9}$/.test(t))return!1;for(var e=0,n=0;n<t.length;n+=3)e+=3*parseInt(t.charAt(n),10)+7*parseInt(t.charAt(n+1),10)+parseInt(t.charAt(n+2),10);return e%10==0},t.ssn=function(t){t=t.trim();return/^[0-8]\d{2}-\d{2}-\d{4}$/.test(t)},t.swiftCode=function(t){t=t.trim();return/^[A-Za-z0-9]{8}([A-Za-z0-9]{3})?$/.test(t)},t.zip=function(t){t=t.trim();return/^\d{5}(\d{4})?$/.test(t)}}));