Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created February 23, 2011 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save huacnlee/840547 to your computer and use it in GitHub Desktop.
Save huacnlee/840547 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