Wish you had given more *different* examples.
Non-consecutive dash or space, okay. But what about dash followed by space or vice versa?
And can the sequence begin or end with a dash or space??
Code:
a1 -b2
c3- d4
-e5-f6
g7-h8-
Are any/all of those valid???
Anyway...assuming that *NONE* of those are legal:
Code:
/^([a-z0-9]+[ \-])*[a-z0-9]+$/i
I think that does it. That's JavaScript regexp notation.
You see it?
Code:
/^ === start
([a-z0-9]+[ \-])* === zero or more of
[a-z0-9]+ === one or more alphanums
[ \-] === followed by either space or dash
[a-z0-9]+ === ending with one or more alphanums
$ === end
/i === ignore case of alphas