LoginSignup
13
16

More than 5 years have passed since last update.

全角半角入り混じった文字列から半角数字のみ抜き出す

Posted at

コード

var num = str.replace(/[^\x01-\x7E]/g, function(s){
    return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
}).replace(/\D/g, '');

参考リンク

http://www.nishishi.com/blog/2013/02/zenkaku_hankaku.html
http://hodade.adam.ne.jp/seiki/page.php?s_zenkaku

13
16
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
16