Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. RegEx for UserName in createuserwizard

RegEx for UserName in createuserwizard

Scheduled Pinned Locked Moved ASP.NET
algorithmsregexhelptutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlexeiXX3
    wrote on last edited by
    #1

    Id like to create a regex expression to add it to the createuserwizard The problem is that im not very familiar with regex, ive been searching, but i cant find an example to do this What id like is the user create a nick with the following restrictions: Between 6 and 20 characters Only letters and numbers and any of this signs (._-) And only one space Ive tried this regex: ^[\wÑñ._-]{6,20}$ How can i restrict the string to have no more than one space (No spaces would be ok) Thanks in advance

    Alexei Rodriguez

    G P 2 Replies Last reply
    0
    • A AlexeiXX3

      Id like to create a regex expression to add it to the createuserwizard The problem is that im not very familiar with regex, ive been searching, but i cant find an example to do this What id like is the user create a nick with the following restrictions: Between 6 and 20 characters Only letters and numbers and any of this signs (._-) And only one space Ive tried this regex: ^[\wÑñ._-]{6,20}$ How can i restrict the string to have no more than one space (No spaces would be ok) Thanks in advance

      Alexei Rodriguez

      G Offline
      G Offline
      gspiteri
      wrote on last edited by
      #2

      This will do exactly what you want with no spaces ^\s{0}[\wÑñ._-]{6,20}$

      A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty I am a Optimist

      A P 2 Replies Last reply
      0
      • G gspiteri

        This will do exactly what you want with no spaces ^\s{0}[\wÑñ._-]{6,20}$

        A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty I am a Optimist

        A Offline
        A Offline
        AlexeiXX3
        wrote on last edited by
        #3

        Thanks for the reply

        gspiteri wrote:

        ^\s{0}[\wÑñ._-]{6,20}$

        This RegEx does exactly what the regex that already have does Besides .-_ and letters and numbers, I need to allow only one space (Optional)

        Alexei Rodriguez

        G 1 Reply Last reply
        0
        • G gspiteri

          This will do exactly what you want with no spaces ^\s{0}[\wÑñ._-]{6,20}$

          A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty I am a Optimist

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          gspiteri wrote:

          This will do exactly what you want with no spaces ^\s{0}[\wÑñ._-]{6,20}$

          \s{0} is completely superfluous. White space is already disallowed because it hasn't been included in the list of character classes contained between the square brackets.

          Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

          1 Reply Last reply
          0
          • A AlexeiXX3

            Thanks for the reply

            gspiteri wrote:

            ^\s{0}[\wÑñ._-]{6,20}$

            This RegEx does exactly what the regex that already have does Besides .-_ and letters and numbers, I need to allow only one space (Optional)

            Alexei Rodriguez

            G Offline
            G Offline
            gspiteri
            wrote on last edited by
            #5

            Oops sorry dude wasnt thinking

            A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty I am a Optimist

            1 Reply Last reply
            0
            • A AlexeiXX3

              Id like to create a regex expression to add it to the createuserwizard The problem is that im not very familiar with regex, ive been searching, but i cant find an example to do this What id like is the user create a nick with the following restrictions: Between 6 and 20 characters Only letters and numbers and any of this signs (._-) And only one space Ive tried this regex: ^[\wÑñ._-]{6,20}$ How can i restrict the string to have no more than one space (No spaces would be ok) Thanks in advance

              Alexei Rodriguez

              P Offline
              P Offline
              pmarfleet
              wrote on last edited by
              #6

              The only way I can think to do this is to use a CustomValidator[^] control. In your custom validation function, first use a regular expression to check that the string is between 6 & 20 characters and contains only letters, numbers, spaces or the (._-) symbols (BTW, the literal '.' character needs to be escaped in a regular expression as \. because '.' is a reserved regular expression character). If your input passes this validation, write some code to count the number of spaces it contains.

              Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

              A 1 Reply Last reply
              0
              • P pmarfleet

                The only way I can think to do this is to use a CustomValidator[^] control. In your custom validation function, first use a regular expression to check that the string is between 6 & 20 characters and contains only letters, numbers, spaces or the (._-) symbols (BTW, the literal '.' character needs to be escaped in a regular expression as \. because '.' is a reserved regular expression character). If your input passes this validation, write some code to count the number of spaces it contains.

                Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

                A Offline
                A Offline
                AlexeiXX3
                wrote on last edited by
                #7

                Thaks for the suggestion, someone at regexlib.com forums helped me with this This does the job: ^(?!.* .* )[\w ñÑ.-]{6,20}$ Weird that . doesnt make the regex fail But ill scape it on my page

                Alexei Rodriguez

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups