Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restrict Special Characters in User Registration 1

Status
Not open for further replies.

LittlBUGer

Programmer
Apr 26, 2006
81
US
Hello. I have an ASP.NET 2.0 website using the "built-in" ASP user management/roles/registration and whatnot. I've created a wizard on a page to do the user registration. One thing I've noticed is that though users can register with spaces in their usernames, anything else other than letters and numbers bombs out due to SQL and such. Since I don't see any reason for anyone using special characters in their usernames, I just want to restrict them from being able to create a user with such characters to make things easy. I think just using a regular expression validator will work but I'm no good at regular expressions. Can anyone help me with this or possibly suggest a better solution? I'm just trying to validate against a simple text box. Thanks.

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
Though I thank you for your reply, I still can't seem to get a regular expression working just right for my scenario. Can someone please help or suggest a different method? Thanks.

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
Code:
^[A-Za-z]\w(?![!@#$%^&*.])

I'm trying to allow all alpha-numeric characters and no special characters. I'd also like to force the first character to be a letter instead of a number, but I'm just not sure if the above is correct...

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
The site I linked to has a "tester" tool which will allow you to test your expression against a value:


Also, by doing a simple search on their site, I found:


which should get you started. There are many other examples like this on their site too.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
I've actually been trying the following out:

Code:
^[A-Za-z]\w+

at this site:
And I keep getting varying results. Meaning it doesn't allow a number to be entered as first char, which is good, but it'll allow certain special chars, which isn't good, unless the results are just confusing me... I'm just confused now. :-\

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
Actually I think I got it now...

Code:
^[A-Za-z]\w{5,19}$

Minimum 6 chars, max 20, no numbers as first char, no special chars. It was the dollar sign at the end that seemed to fix it. Thanks for the help and sorry to bother you over something so simple. :)

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top