LoginSignup
1
2

More than 3 years have passed since last update.

JavaScriptで正規表現を使って対象文字列が意図した文字列か判定する方法

Last updated at Posted at 2019-07-04

例えば6桁の半角英数字のみTrueにしたい場合、

hoge.js
const hoge = 'abc123';
const hogeRegExp = new RegExp('^[a-zA-Z0-9]{6}$');
if(hogeRegExp.test(hoge)){
   console.log('true');
}else{
   console.log('false');
}
//trueが表示される
1
2
0

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
1
2