Validate username in php

,

Use this simple code to validate the usernames in php ( maybe you need to a user registration ). The username will have only characters, numbers and _ (underscore)

$username="your username";
  if(!preg_match("/^[\.A-z0-9_\-]{1,15}$/i", $username)) echo "Your username must only contain valid characters, numbers and _";


Comments are closed.