Murray
Murray

Reputation: 73

Regex for Username?

I am using C# and jQuery to valid a username with Regex. Just learning :) So far I have

UserName = "[a-zA-Z0-9]";

But this doesn't stop symbols ? How to ensure that no symbols or " . " or " _ " ?

Thanks

Upvotes: 7

Views: 10665

Answers (2)

Asim Ali
Asim Ali

Reputation: 19

you can also add @ , . %^&* digits character in below regex @"^[a-zA-Z0-9._@#$% ]+$"

Upvotes: 0

Quentin
Quentin

Reputation: 944442

That regex says "At least one letter or number" you want "Every character from the start to the end is a letter or number"

"^[a-zA-Z0-9]+$"

Upvotes: 16

Related Questions