You can combine the use of $replace and $mknickfn(nickname) to replace and remove invalid characters:
$replace($mknickfn(NickHere),[,_,],_)