• Hello,

    Does anyone know if it is possible to restrict usernames to numbers only?

    Also, is it possible to restrict the number length to, say, 10? No more and no less.

    I am in the early stages of putting together a business case for a client who requires only numbers to be used as a username. This number is a unique identifier to their staff in their organisation, for example: 2398253635.

    Any help and guidance very much appreciated.

    Paul.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi Paul,

    WordPress allows usernames made up entirely of numbers, so it’s definitely possible.

    How are you going to be creating the users? Will people be setting up their own accounts, or will someone be entering them, or importing?

    There are already some plugins that let you restrict usernames on registration, or you can write your own code or make rules in a plugin like Gravity Forms or BuddyPress.

    Thread Starter Bat n Ball

    (@bat-n-ball)

    Hi ancawonka,

    The new users will create their own accounts but admins may, from time to time, create an account for the users of the website.

    The username restrictions are not that important when admins create accounts, as they will know what the format should be, but when a new visitor registers, the ‘number-only’ username restrictions need to apply.

    I would be quite happy with some kind of light-weight plugin but wouldn’t want to install full blown forum or social plugins just to implement username restrictions.

    I’m also quite happy to do some code editing.

    Many thanks for your reply ??

    Paul.

    Thread Starter Bat n Ball

    (@bat-n-ball)

    Ooops! Almost forgotten to mention…

    The new website will be multisite. I know there are already username restrictions with multisite, i.e., lowercase letters and numbers only. I just need the numbers ??

    I didn’t post in the multisite forum because I thought this was more hack-specific.

    Kind regards,

    Paul.

    If you are cool w/ doing your own coding, you can set up your own registration form with whatever restrictions you want.

    This tutorial is a reasonable starting point: https://code.tutsplus.com/tutorials/creating-a-custom-wordpress-registration-form-plugin–cms-20968

    Also take a look at the plugins available for custom user registration forms – you can look at their code to see how it’s set up.

    Since you are going to be creating a registration form on a multisite, you may have to show the form on a page only within the main site (allowing people to register there).

    How are people added to the additional sites? Through an admin action?

    Thread Starter Bat n Ball

    (@bat-n-ball)

    Hi ancawonka,

    Thank you for your reply and sorry for my late reply!

    I will certainly have a read of your tutorial today when I find an hour or two’s spare time ??

    I don’t think I mentioned WooCommerce, which will be the reason why users would want to register in the first place. WooCommerce has it’s own user registration page but, as you say, it would probably be better to create a custom registration form rather than edit the existing WordPress or WooCommerce forms.

    Each multisite would have its own WooCommerce store which makes things slightly complicated. At this moment in time, I think users will register on one multisite only. I have seen a plugin which also registers users across a network and will look into that.

    When a user registers on a multisite network, they are restricted to lowercase letters and numbers only. Am I being naive in assuming only the letters part of the username sanitization needs to be removed, if I want to use numbers only?

    As complicated as this might sound, I’m fairly confident something can be put together ??

    Kind regards,

    Paul.

    Thread Starter Bat n Ball

    (@bat-n-ball)

    P.S.

    Just reading the article you linked to. This is excellent and will help me a great deal. Thank you.

    Hi Paul,

    Ooh, you definitely don’t want them to register through WooCommerce – WooCommerce automatically puts in the part before the @ in the email address as the username.

    You can definitely make this happen. There’s just quite a bit of research to do.

    Pete

    (@perthmetro)

    Yes, I recently saw a plugin that allows the user id to be their login username… try searching for it.

    Pete

    (@perthmetro)

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Number-only username?’ is closed to new replies.