Created
November 1, 2014 04:57
-
-
Save youcune/d2302ccfb401d48fee79 to your computer and use it in GitHub Desktop.
電話番号とかメールアドレスを全角で入力しちゃう人に優しくできるかもしれない String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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