Skip to main content

validate_identifier_format

Function validate_identifier_format 

Source
fn validate_identifier_format(
    name: &str,
    kind: IdentifierKind,
) -> Result<(), String>
Expand description

Validates an identifier follows naming rules.

§Rules

  • Start Character: Must begin with a lowercase letter (a-z, including letters with diacritical marks and non-Latin letters) or an underscore (_).
  • Subsequent Characters: Can include lowercase letters, digits (0-9), underscores (_), or dollar signs ($).
  • Case: All characters must be lowercase.

§Arguments

  • name - The identifier name to validate
  • kind - The type of identifier (for error messages)

§Returns

  • Ok(()) if the identifier is valid
  • Err(String) with a descriptive error message if invalid

§Examples

Valid identifiers:
  users, _temp, my_table, café, 日本語, user123, price$

Invalid identifiers:
  Users (uppercase)
  123table (starts with digit)
  my-table (contains hyphen)
  MY_TABLE (uppercase)