Skip to main content

is_valid_username

Function is_valid_username 

Source
pub fn is_valid_username(label: &str) -> bool
Expand description

Check if a username is valid according to DPNS rules

A username is valid if:

  • It’s between 3 and 63 characters long
  • It starts and ends with alphanumeric characters (a-zA-Z0-9)
  • It contains only alphanumeric characters and hyphens
  • It doesn’t have consecutive hyphens (enforced by the pattern)

Pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$

§Arguments

  • label - The username label to check (e.g., “alice”)

§Returns

Returns true if the username is valid, false otherwise