Advertisement
Shell_Casing

code check

Oct 13th, 2020
2,367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default function checkCode(code) {
  2.  
  3.     if(code.length !== 17) return false;
  4.  
  5.     if(code.slice(0, 2).toLowerCase() !== 'af') return false;
  6.  
  7.     if(/^\d+$/.test(cr_code.slice(2)) !== true) return false;
  8.  
  9.     const datePart = code.slice(2, 10);
  10.  
  11.     const ISO_DATE = datePart.substring(0, 4) + '-' + datePart.substring(4, 6) + '-' + datePart.substring(6);
  12.  
  13.     if(typeof(Date.parse(ISO_DATE)) != 'number') return false;
  14.  
  15.     return true;
  16.  
  17. };
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement