JWT token string to validate
True if token has valid JWT structure, false otherwise
// Validate token format before verification
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
const isValidFormat = validateTokenFormat(token);
if (isValidFormat) {
// Proceed with cryptographic verification
const decoded = jwt.verify(token, secret);
} else {
console.log('Invalid token format');
}
Validate JWT token format and structure without verification
Performs basic structural validation of a JWT token without cryptographic verification. Checks that the token has the correct three-part format (header.payload.signature) and contains required JWT claims in the header and payload sections.
This function is useful for quick format validation before attempting expensive cryptographic verification. It helps filter out obviously malformed tokens and provides early validation in authentication flows.