On my registration page I need to validate the usernames as alphanumeric only, but also with optional underscores. I\'ve come up with this:
function validate
Looks fine to me. Note that you make no requirement for the placement of the underscore, so "username_" and "___username" would both pass.