Hello,
Try this:
$eregstr2="(string[0-9_-]*)$";
if(!ereg($eregstr2,$str)){
echo "The user name is not available.";
exit;
} //endif
If that doesn't work, remove the caret () or the $ and try that. If that doesn't work, strip your pattern down to its most simple level and build it up slowly from there. In this case, make your pattern "string2" and make sure that's working. Then go to "string[0-9]" and make sure that works. Add more restrictions as you go, that way you can debug along the way.