Ad

short implementation with regular expresion

Code
Diff
  • function pinValidator(pin){
      return !!pin.match(/^\d{4}$/);
    }
    
    • function pinValidator(pin){
    • if (![4,6].includes(pin.length)) return false
    • if (pin.match(/^\d+$/)) return true
    • return false
    • return !!pin.match(/^\d{4}$/);
    • }