Jump to content

Help with regex on a valid username


cooldude832

Recommended Posts

A simple bit of regex:

<?php

$username = 'c00l_Dude'; // valid
//$username = 'cooldude832'; // valid
//$username = 'c00l'; // Invalid
//$username = 'Cool-Dude'; // Invalid

if(preg_match('/^([A-Z0-9_]){5,}$/i', $username))
{
    echo $username . ' -  Valid';
}
else
{
    echo $username . ' -  Invalid';
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.