Skip to content

Instantly share code, notes, and snippets.

@superbiche
Created March 29, 2015 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superbiche/6794d6e1876ff75c099d to your computer and use it in GitHub Desktop.
Save superbiche/6794d6e1876ff75c099d to your computer and use it in GitHub Desktop.
Validate string that must contain only alphanumeric values and eventually an underscore as separator. From http://stackoverflow.com/questions/1330693/validate-username-as-alphanumeric-with-underscores
$is_valid = preg_match('/^[A-Za-z][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*$/', $str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment