Skip to content

Instantly share code, notes, and snippets.

@youcune
Created November 1, 2014 04:57
Show Gist options
  • Save youcune/d2302ccfb401d48fee79 to your computer and use it in GitHub Desktop.
Save youcune/d2302ccfb401d48fee79 to your computer and use it in GitHub Desktop.
電話番号とかメールアドレスを全角で入力しちゃう人に優しくできるかもしれない String
require 'nkf'
class String
HYPHEN_LOOKING_CHARS = /[\u00AD\u2011-\u2015\u2043\uFE63\u2212\u207B\u208B\uFF0D\u30FC]/
# self を半角にした文字列を返す
# @return [String] 半角にした文字列
def hankaku
NKF.nkf('-wWm0Z1', self).gsub(HYPHEN_LOOKING_CHARS, '-')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment