govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

Add IsJWT validation function, tests, and README entry (Fixes #502)

Open shushantrishav opened this issue 9 months ago • 0 comments

Q A
Documentation yes
Bugfix no
BC Break no
New Feature yes
RFC yes
QA yes

Description

This PR adds a new validator function IsJWT() to the govalidator package.

Why this change is necessary: Currently, JWT strings can only be validated using a manual regex inside a valid:"matches(...)" struct tag, which is not very convenient or readable. As per RFC-7519, a JWT is represented as a sequence of three URL-safe base64-encoded strings separated by periods ('.'). This PR implements a native validation function to improve developer ergonomics and code readability.

What this PR does:

  • Implements a new IsJWT() function using a compiled regex pattern.
  • Adds corresponding unit tests in validator_test.go.
  • Updates the README.md function list to include the new IsJWT() function.

Target branch: master

shushantrishav avatar Jun 27 '25 11:06 shushantrishav