LoginSignup
0
0

More than 1 year has passed since last update.

[javascript] ISO stringを判定する正規表現

Posted at

結論

const reg = /^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))$|^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))$|^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))$/

テスト

console.log(reg.test("2022-04-20T11:32:00.000-04:00")) // => true
console.log(reg.test("2022-04-2011:32:00.000-04:00")) // => false
console.log(reg.test("2022-04-20")) // => false
console.log(reg.test("2022-W17-7")) // => false
console.log(reg.test("11:32:00.000-04:00")) // => false

参考

0
0
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
0
0