I have this Regex I modified to allow underscores, hyphen, letters and numbers. I am trying to modify it further so that it has the following properties:
Try this:
^[a-zA-Z0-9](?:[a-zA-Z0-9_-]*[a-zA-Z0-9])?$
Or this, which will simply ensure that the string does not start with a hyphen or underscore:
^[a-zA-Z0-9][a-zA-Z0-9_-]*$
^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9_-]*[a-zA-Z0-9])$
Either one of the three possibilities:
[a-zA-Z0-9]
[a-zA-Z0-9][a-zA-Z0-9]
[a-zA-Z0-9][a-zA-Z0-9_-]*[a-zA-Z0-9]