REGEXVAULTv2.0
Identity & PII/Digital Identity
Verified Safe

OAuth / OpenID Connect Sub Claim Regex for Java

/^[A-Za-z0-9\-._|]{8,255}$/

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching oauth / openid connect sub claim, ported and verified for Java. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.

Java Implementation

Java
// OAuth / OpenID Connect Sub Claim
// ReDoS-safe | RegexVault — Identity & PII > Digital Identity

import java.util.regex.Pattern;

public class OauthOpenidConnectSubClaimValidator {
    private static final Pattern PATTERN =
        Pattern.compile("^[A-Za-z0-9\\-._|]{8,255}$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("248289761001")); // true
    }
}

Test Cases

Matches (Valid)
Rejects (Invalid)
248289761001ab
user123456user@name
auth0|507f191e810c19729de860eauser name
google-oauth2|1234567890

When to use this pattern

This pattern is drawn from the Identity & PII > Digital Identity category and carries a ReDoS-safe certification. That matters for Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

The OIDC sub claim should be opaque — do not encode personal data in it. If it contains a username or email, it violates the spirit of the OIDC specification and creates privacy risks.

Technical Notes

OIDC sub (subject) is a locally unique, never-reassigned identifier for the end user. Format is provider-specific: Google uses numeric strings, Auth0 uses provider|id format, Okta uses UUID format. Must be stable and not reassigned.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern