I\'m trying to create a regular expression to validate usernames against these criteria:
I guess you'd have to use Lookahead expressions here. http://www.regular-expressions.info/lookaround.html
Try
^[a-zA-Z0-9](_(?!(\.|_))|\.(?!(_|\.))|[a-zA-Z0-9]){6,18}[a-zA-Z0-9]$
[a-zA-Z0-9] an alphanumeric THEN (
_(?!\.) a _ not followed by a . OR
\.(?!_) a . not followed by a _ OR
[a-zA-Z0-9] an alphanumeric ) FOR
{6,18} minimum 6 to maximum 18 times THEN
[a-zA-Z0-9] an alphanumeric
(First character is alphanum, then 6 to 18 characters, last character is alphanum, 6+2=8, 18+2=20)