The username string to validate.
Optionaloptions: { includeInErrors?: boolean }OptionalincludeInErrors?: booleanWhen true, validation errors are stored in the
global error manager under the username field. Defaults to false.
A UsernameValidationResult object with:
isValid — true if the username satisfies all configured rules.errors — an array of per-rule validation errors with code, message, and isValid.import { useUsernameValidation } from "@auth0/auth0-acul-react/signup";
export function UsernameField() {
const { isValid, errors } = useUsernameValidation(username, { includeInErrors: true });
return (
<div>
<input
value={username}
onChange={e => setUsername(e.target.value)}
aria-invalid={!isValid}
/>
{!isValid && (
<ul>
{errors.map(err => (
<li key={err.code}>{err.message}</li>
))}
</ul>
)}
</div>
);
}
React hook for validating a username against the current Auth0 username policy.
This hook checks the provided username against all configured validation rules and returns a structured result describing whether it passes. Optionally, it can send validation errors to the global error manager so that UI components observing the
usernamefield can automatically display or react to these errors.