• Resolved frederico3385

    (@frederico3385)


    I would like to know how to limit the user name in the registry, I would leave the username at most 14 characters.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could probably do it via some JavaScript on the sign-up/login page, added using login_enqueue_scripts. I don’t believe that there’s any built-in way to do it by default.

    Moderator bcworkz

    (@bcworkz)

    The problem with JS script is users can get around any imposed restrictions by disabling JS on their browser. To securely impose restrictions, it must be done server side. The use of JS is still a good idea from a UX standpoint, but enforce server side.

    Catacaustic is correct, there is no built in setting to manage username length, but it can be enforced by hooking the ‘validate_username’ filter and returning false if the name is too long, otherwise return the passed value.

    In returning false, the error message “This username is invalid because it uses illegal characters. Please enter a valid username.” is returned, which is rather misleading.

    You can alter the message by hooking ‘registration_errors’ and modifying the passed WP_Error object. You should check the username again for length to be sure the error is because of length and not some other problem.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Character limit’ is closed to new replies.