RegEx for UserName in createuserwizard
-
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
-
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
-
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
-
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
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
-
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
-
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
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
-
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
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