[Solved] PHP Regex for Username? [duplicate]


This:

$newStr = preg_replace('/[^a-z0-9]/i', '_', $str);

should be:

$newStr = preg_replace('/[^a-zA-Z0-9!@#$-]/', '_', $str);

The code below should strip out:

‘”/\;?”

<?php
        $newStr = preg_replace('/[^a-zA-Z0-9!@#$-]/', '_', "test\'\"\/\\\;\?");
        echo $newStr;
?>

Which produces:

test__________%

4

solved PHP Regex for Username? [duplicate]