views:

88

answers:

1

Hi Guys,

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

+5  A: 

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]+$"
David Dorward
oh great thanks :) wow fast reply! ill try this. thanks so much
Murray
great! thanks again :))))
Murray
As an addition, typically usernames are not allowed to start with digits - to ensure this, use `"^[a-zA-Z][a-zA-Z0-9]*$"`.
Péter Török
And if you want min/max length restrictions: `"^[a-zA-Z][a-zA-Z0-9]{3,9}$"` (min 4 and max 10)
Amarghosh
so this works ? ^[a-zA-Z0-9]{3,11}$ - for no symbols, min/max 3-11 ?
Murray
@Gabriel: check that again; Murray removed the separate letter in the front.
Alan Moore