+1  A: 

maybe you should escape the dots

\.
catwalk
+1 thanks for pointing that out!
Galilyou
A: 

And \w means [A-Za-z0-9_]. What is why it matches "1234"

skwllsp
+2  A: 

Problems observed with your regex
1. "." is a meta character in regex. It matches "anything". You should escape it to match the dot. Like this .
2. \w is a character class which includes small letters, caps, numbers and underscore. This explains why "1234" passed.

Try this

^[a-zA-Z]\w*(\.[-\w]+){1,2}$
Jass
Just one small nitpick: most regex implementations do not let the DOT match `\r` and `\n` unless the DOT-ALL option `(?s)` is enabled.
Bart Kiers
Thanks for the explanation, but your Regex didn't match anything of the patterns above!
Galilyou
@7alwagy not sure what you mean? i tried on regexpal.com and it did match perfectly. Do you like have this list in a file and doing a one by one search to match them or something ? then you should probably get rid of the ^,$
Jass
Specifically something like (john.al-smith) was not matched by your regex.
Galilyou
Here's a list of the unmatched patterns (using RegexDesigner): "john.al-caboon", "john.smith.1", "john.al-smith.1"
Galilyou
i dint know john.1a was valid. fixed it a bit now. for john.al-smith is that like with brackets? it will match without the brackets for sure
Jass
try it at www.regexpal.com. You could test it and make minor modifications to suit your needs.
Jass
@Jasss, I did try at regexpal, and it's working! Don't know what's wring with RegexDesigner. Will try again with RegexCoach. Thanks anyways +1
Galilyou
Working on RegexCoach! Thanks a lot Jass. Winner!
Galilyou
A: 

Use this expression: \w+\S*?\.\w+\S*

I read your definition as:

  • at least one character
  • mandatory dot
  • at least one character

This ran successfully using .NET RegexOptions.ECMAScript and RegexOptions.Multiline

Rubens Farias