Function validateHandleFormat

  • This validates a handle format.

    A correct handle must be:

    1. between 3 and 31 characters
    2. only contain [a-z0-9-_]

    Optional:

    1. not be an Ethereum address (when disallowAddress is set to true; false by default)

    Some correct handles examples:

    • abcdefg
    • my-handle
    • my-handle_123

    Some incorrect handles examples:

    • ab (too short)
    • my handle (contains space)
    • my-handle! (contains !)
    • WhatIsThis (contains uppercase)

    Parameters

    • value: string
    • __namedParameters: {
          disallowAddress?: boolean;
      } = {}
      • Optional disallowAddress?: boolean

        Whether to disallow Ethereum addresses as handles.

        This is normally used when registering a handle for a user, because Ethereum addresses are not allowed as handles when creating a character.

        But note that there are some characters that have Ethereum addresses as handles. This is because they were created by the createThenLinkCharacter contract method.

        Default

        false.

    Returns {
        code: "valid";
        message: null;
        valid: true;
    } | {
        code: "invalidLength" | "invalidChars" | "shouldNotBeAddress" | "notAString";
        message: string;
        valid: false;
    }

    An object with valid and message properties. If valid is true, then the handle is valid. If valid is false, then the handle is invalid, and the message property contains the reason why it is invalid.

    Example

    const { valid, message } = contract.character.validateHandle('my-handle')
    if (!valid) {
    throw new Error(message)
    }

Generated using TypeDoc