Skip to content

Instantly share code, notes, and snippets.

@huobazi
Forked from huacnlee/safe_login.rb
Created May 16, 2011 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huobazi/973840 to your computer and use it in GitHub Desktop.
Save huobazi/973840 to your computer and use it in GitHub Desktop.
去掉字符里面的非法字符,用于处理用户名 a-z 0-9 - _
def safe_login(str)
str.gsub(/[^a-z0-9\-_]/,'')
end
# Test
ruby-1.9.2-p0 > safe_login("asdlg1-24_1(*&(sdgsdg")
=> "asdlg1-24_1sdgsdg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment