Problem with Regex in .NET (C#)
Posted
by Craig Bovis
on Stack Overflow
See other posts from Stack Overflow
or by Craig Bovis
Published on 2010-05-05T11:52:31Z
Indexed on
2010/05/05
12:08 UTC
Read the original article
Hit count: 490
I'm trying to write a a regex to validate a string to match the following rules.
- Must start with a-z (case insensitive)
- Must only contain a-z A-Z 0-9 . -
I've put something together based on my limited knowledge and ran it through an online testing tool for a whole bunch of situations and the results were as I had hoped however when I place the pattern into my .NET code it doesn't match correctly.
The pattern I am using is,
[a-zA-Z][a-zA-Z0-9.\-]*
Is this the correct pattern or am I barking up the wrong tree?
Some examples of what I'm expecting.
- craig.bovis - VALID
- 24craig - INVALID
- craig@bovis - INVALID
- craig24 - VALID
- -craig24 - INVALID
- craig24.bovis-test - VALID
© Stack Overflow or respective owner