You have received regular expressions in this thread that answer your specific question. You do a blacklisted approach (blocking characters you don't need), but is it really better? I see that you did not cover and / or ~, and there are many other special characters that are probably still missing.
, " " pablorc regexp. , ... : , .
, .
def valid_login?(str)
return true if (/^\w*$/.match(str))
return false
end
valid_login?, true, , , ( , , ) .
:
> valid_login?("testy")
true
> valid_login?("a b")
false
> valid_login?("a'")
false