• Resolved wildapache

    (@wildapache)


    I want to allow only user name with small a-z and dot and underscore only in a middle !

    I have this regex : ^[a-z_.]$

    But how to allow dot and underscore only in a middle and not at start and of at end of the string ?

    Thanks

    • This topic was modified 1 week, 6 days ago by wildapache.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator threadi

    (@threadi)

    This one could help:

    ^[a-z]([a-z._]*[a-z])?$

    When it comes to WordPress, however, you also need to use it with an appropriate hook. That would be validate_username or registration_errors. If you’re dealing with a multisite installation, it’s more likely to be wpmu_validate_user_signup.

    Thread Starter wildapache

    (@wildapache)

    Thanks it works.

    I want to add another thing.

    Allow only 1 dot or 1 underscore, to deny to user write in way : user.na_me

    Moderator threadi

    (@threadi)

    Try this:

    ^[a-z]+([._][a-z]+)?$

    And take a look at some basics on regular expressions: https://www.php.net/manual/en/reference.pcre.pattern.syntax.php (yeah, I had to go through that too). It doesn’t really have anything to do with WordPress.

    Thread Starter wildapache

    (@wildapache)

    Works !

    Thank you so much, I can’t make a deep internet research now, to makes regex it at my own.

    Looked at the regex info list I tried to added at the end of regex {4,15} min/max but it works not correct.

    For example it’s start to count min from 5 and not 4

    Thread Starter wildapache

    (@wildapache)

    On this case not possible to count whole regex chars ?

    Read a little bit about quantifier, so quantifier can’t count whole groups of regex ? only some part ? And it can’t be sum in the end ?

    • This reply was modified 1 week, 5 days ago by wildapache.
Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.