{"id":5619,"date":"2020-01-13T23:51:00","date_gmt":"2020-01-13T14:51:00","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=5619"},"modified":"2020-01-14T17:15:12","modified_gmt":"2020-01-14T08:15:12","slug":"%e5%ae%9f%e4%be%8b%e3%83%bb%e5%85%a861%e4%bb%b6%ef%bc%81express%e3%81%a7%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%99%e3%82%8b%e3%80%8cexpress-validator%e3%80%8d","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=5619","title":{"rendered":"\u5b9f\u4f8b\u30fb\u516861\u4ef6\uff01Express\u3067\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3059\u308b\u300cexpress-validator\u300d"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u3053\u6570\u56de\u306f\u9ad8\u901f\u306a\u30b5\u30a4\u30c8\u3092\u69cb\u7bc9\u3059\u308b\u6d41\u308c\u3067<code>Node.js<\/code>\u306e<code>Express<\/code>\u3092\u4f7f\u3063\u305f\u958b\u767a\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><code>Express<\/code>\u306f<code>Laravel<\/code>\u3068\u6bd4\u3079\u308b\u3068\u3001\u3088\u308a\u5fc5\u8981\u306a\u3082\u306e\u3060\u3051\u306b\u7279\u5316\u3057\u305f\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u300c\u3044\u305f\u308c\u308a\u3064\u304f\u305b\u308a\u300d\u306e<code>Laravel<\/code>\u3068\u306f\u307e\u305f\u9055\u3063\u305f\u96f0\u56f2\u6c17\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u306f\u305d\u306e\u300c<strong>\u6a19\u6e96\u642d\u8f09\u3055\u308c\u3066\u306f\u3044\u306a\u3044\u3082\u306e<\/strong>\u300d\u306e\u4e2d\u304b\u3089\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\uff08\u5165\u529b\u304c\u6b63\u3057\u3044\uff0f\u9593\u9055\u3063\u3066\u308b\u306e\u30c1\u30a7\u30c3\u30af\uff09<\/strong><\/p>\n<p>\u306e\u4f7f\u3044\u65b9\u3092\u5b9f\u4f8b\u3067\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3566 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1.png\" alt=\"\" width=\"306\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1.png 306w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1-287x300.png 287w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Node 8.10\u3001Express 4.1\u3001express-validator 6.3<\/p>\n<h1>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h1>\n<p>\u307e\u305a\u306f\u3001<code>Express<\/code>\u3067\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u300c<strong>express-validator<\/strong>\u300d\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>npm install --save express-validator<\/strong>\r\n<\/pre>\n<h1>\u6e96\u5099\u3059\u308b<\/h1>\n<p>\u300c<strong>express-validator<\/strong>\u300d\u3092\u4f7f\u3046\u306b\u306f\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u8aad\u307f\u8fbc\u307f\u3068\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u8a2d\u5b9a\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u9069\u5f53\u306a\u4f4d\u7f6e\u306b\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>const { check, validationResult } = require('express-validator');\r\napp.use(express.json());\r\napp.use(express.urlencoded({ extended: true }));\r\n<\/strong><\/pre>\n<h1 id=\"basic_usage\">\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h1>\n<p>\u300c<strong>express-validator<\/strong>\u300d\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u30eb\u30fc\u30c8\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>app.post('\/user\/', <strong>[\r\n  check('value1')<\/strong><strong>.not().isEmpty().isEmail(),<\/strong>\r\n<strong>  check('value2').isNumeric() <\/strong>\r\n<strong>\r\n]<\/strong>, (req, res) =&gt; {\r\n\r\n  <strong>const errors = validationResult(req);\r\n\r\n  if(!errors.isEmpty()) {<\/strong> \/\/ \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u5931\u6557<strong>\r\n\r\n    return res.status(422).json({ errors: errors.array() });\r\n\r\n  }\r\n\r\n  <\/strong>\/\/ \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6210\u529f<strong>\r\n  res.json({ result: true });<\/strong>\r\n\r\n});<\/pre>\n<p>\u203b<code>check()<\/code>\u306e\u90e8\u5206\u306f<code>.<\/code>\u3067\u7e4b\u3044\u3067\u3044\u304f\u3064\u3082\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002<br \/>\n\u203b\u307e\u305f\u3001<code>check()<\/code>\u306f\u914d\u5217\u3067\u597d\u304d\u306a\u3060\u3051\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<h1>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30eb\u30fc\u30eb\u306e\u4e00\u89a7<\/h1>\n<p>\u300c<strong>express-validator<\/strong>\u300d\uff08\u5185\u90e8\u7684\u306f <strong><a href=\"https:\/\/validatejs.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">validator.js<\/a><\/strong>\u00a0\u3092\u4f7f\u3063\u3066\u307e\u3059\uff09\u306b\u306f\u305f\u304f\u3055\u3093\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30eb\u30fc\u30eb\u304c\u5b58\u5728\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\uff11\u3064\u305a\u3064\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u203b\u305f\u3060\u3057\u3001\u30b3\u30fc\u30c9\u304c\u9577\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001<code>check()...<\/code>\u306e\u90e8\u5206\u306e\u307f\u3092\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3059\u3002\u5b9f\u969b\u306e\u4f7f\u3044\u65b9\u306f\u3001<a href=\"#basic_usage\">\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u7a7a\u767d\u3067\u306f\u306a\u3044\u304b\u3069\u3046\u304b\uff08\u5fc5\u9808\u9805\u76ee\uff09<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u540d\u524d\u306e\u5165\u529b\u3092\u5fc5\u9808\u9805\u76ee\u306b\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>not().isEmpty()<\/strong>;<\/pre>\n<h2>\u7279\u5b9a\u306e\u6587\u5b57\u5217\u3092\u542b\u3093\u3067\u3044\u308b\u304b\u3069\u3046\u304b\uff1acontains()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u30c6\u30b9\u30c8\u300d\u3068\u3044\u3046\u6587\u5b57\u304c\u5165\u529b\u5185\u5bb9\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>contains('\u30c6\u30b9\u30c8')\r\n<\/strong><\/pre>\n<h2>\u5165\u529b\u3057\u305f\uff12\u3064\u306e\u5024\u304c\u4e00\u81f4\u3059\u308b\u304b\u3069\u3046\u304b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c<strong>\u30d1\u30b9\u30ef\u30fc\u30c9<\/strong>\u300d\u3068\u300c<strong>\u30d1\u30b9\u30ef\u30fc\u30c9\uff08\u78ba\u8a8d\uff09<\/strong>\u300d\u306e\u5185\u5bb9\u304c\u4e00\u81f4\u3059\u308b\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('password')\r\n  .<strong>custom((value, { req }) =&gt; {\r\n\r\n    if(req.body.password !== req.body.passwordConfirmation) {\r\n\r\n      throw new Error('\u30d1\u30b9\u30ef\u30fc\u30c9\uff08\u78ba\u8a8d\uff09\u3068\u4e00\u81f4\u3057\u307e\u305b\u3093\u3002');\r\n\r\n    }\r\n\r\n    return true;\r\n\r\n  })<\/strong><\/pre>\n<p>\u203b \u5b9f\u306f\u3001\u5185\u90e8\u7684\u306b\u4f7f\u3063\u3066\u3044\u308b<code>validator.js<\/code>\u306b\u306f<code>equals()<\/code>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001<code>check()<\/code>\u3092\u4f7f\u3046\u4f4d\u7f6e\u3067\u306f\u6bd4\u8f03\u3059\u308b\u5024\u3092\u53d6\u5f97\u3067\u304d\u306a\u3044\u306e\u3067<code>custom()<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u7279\u5b9a\u306e\u65e5\u4ed8\u3088\u308a\u5f8c\u304b\u3069\u3046\u304b\uff1a isAfter()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c<strong>2000\u5e741\u670815\u65e5<\/strong>\u300d\u3088\u308a\u3082<strong>\u5f8c\u306e\u65e5\u4ed8\u304b\u3069\u3046\u304b<\/strong>\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isAfter('2000-01-15')<\/strong><\/pre>\n<p>\u203b \u3064\u307e\u308a\u3001\u300c2000-01-16\u300d\u4ee5\u964d\u306e\u65e5\u4ed8\u3060\u3068\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u7279\u5b9a\u306e\u65e5\u4ed8\u3088\u308a\u524d\u304b\u3069\u3046\u304b\uff1a isBefore()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c<strong>2000\u5e741\u670815\u65e5<\/strong>\u300d\u3088\u308a\u3082<strong>\u524d\u306e\u65e5\u4ed8\u304b\u3069\u3046\u304b<\/strong>\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name')<strong>.isBefore('2000-01-15')\r\n<\/strong><\/pre>\n<p>\u203b \u3064\u307e\u308a\u3001\u300c2000-01-14\u300d\u4ee5\u524d\u306e\u65e5\u4ed8\u3060\u3068\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u304b\u3069\u3046\u304b\uff1a isAlpha()<\/h2>\n<pre>check('attribute_name')<strong>.isAlpha()<\/strong><\/pre>\n<p>\u203b \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3067\u304d\u308b\u306e\u306f\u3001\u534a\u89d2\u306e<code>a\u301cz<\/code>\u3068<code>A\u301cZ<\/code>\u3067\u3059\u3002<\/p>\n<h2>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u3068\u6570\u5b57\u304b\u3069\u3046\u304b\uff1a isAlphanumeric()<\/h2>\n<pre>check('attribute_name')<strong>.isAlphanumeric()<\/strong><\/pre>\n<p>\u203b \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3067\u304d\u308b\u306e\u306f\u3001\u534a\u89d2\u306e<code>a\u301cz<\/code>\u3068<code>A\u301cZ<\/code>\u3001<code>1\u301c9<\/code>\u3067\u3059\u3002<\/p>\n<h2>\u30a2\u30b9\u30ad\u30fc\u6587\u5b57\u304b\u3069\u3046\u304b\uff1a isAscii()<\/h2>\n<pre>check('attribute_name')<strong>.isAscii()<\/strong><\/pre>\n<p>\u203b \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3067\u304d\u308b\u306e\u306f\u3001\u534a\u89d2\u306e<code>a\u301cz<\/code>\u3068<code>A\u301cZ<\/code>\u3001\u305d\u3057\u3066<code>!<\/code>\u3084<code>*<\/code>\u306a\u3069\u306e\u30a2\u30b9\u30ad\u30fc\u6587\u5b57\u3067\u3059\u3002\uff08\u5168\u89d2\u6587\u5b57\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\uff09<\/p>\n<h2>Base32\u3067\u30a8\u30f3\u30b3\u30fc\u30c9\u3057\u305f\u6587\u5b57\u5217\u304b\u3069\u3046\u304b\uff1a isBase32()<\/h2>\n<pre><strong>check('attribute_name').isBase32()<\/strong><\/pre>\n<h2>Base64\u3067\u30a8\u30f3\u30b3\u30fc\u30c9\u3057\u305f\u6587\u5b57\u5217\u304b\u3069\u3046\u304b\uff1a isBase64()<\/h2>\n<pre><strong>check('attribute_name').isBase64()<\/strong><\/pre>\n<h2>boolean\u5024\u304b\u304b\u3069\u3046\u304b: isBoolean()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u5165\u529b\u304c\u300ctrue\u300d\u3082\u3057\u304f\u306f\u300cfalse\u300d\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name')<strong>.isBoolean()<\/strong><\/pre>\n<p>\u203b \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3059\u308b\u306e\u306f<strong>\u534a\u89d2\u5c0f\u6587\u5b57\u306e\u300ctrue\u300d\u3068\u300cfalse\u300d<\/strong>\u3060\u3051\u3067\u3059\u3002<\/p>\n<h2 id=\"isLength\">\u6587\u5b57\u5217\u306e\u9577\u3055\u304c\u6307\u5b9a\u3057\u305f\u7bc4\u56f2\u5185\u304b\u3069\u3046\u304b\uff1a isLength()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u5217\u306e\u9577\u3055\u304c<code>0\u301c5<\/code>\u306e\u7bc4\u56f2\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isLength({ min:3, max:5 })<\/strong><\/pre>\n<p>\u203b \u5168\u89d2\u30fb\u534a\u89d2\u95a2\u4fc2\u306a\u304f\u5358\u7d14\u306b\u6587\u5b57\u306e\u6570\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5f62\u5f0f\u3067\u3059\u3002\u3082\u3057\u30d0\u30a4\u30c8\u9577\u3055\u3092\u30c1\u30a7\u30c3\u30af\u3057\u305f\u3044\u5834\u5408\u306f\u3001<a href=\"#isByteLength\">isByteLength()<\/a>\u3092\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2 id=\"isByteLength\">\u6587\u5b57\u5217\u306e\u30d0\u30a4\u30c8\u9577\u304c\u6307\u5b9a\u3057\u305f\u7bc4\u56f2\u5185\u304b\u3069\u3046\u304b\uff1a isByteLength()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u5217\u306e\u30d0\u30a4\u30c8\u9577\u304c\uff08<code>UTF-8<\/code>\u3068\u3057\u3066\uff09<code>0\u301c5<\/code>\u306e\u7bc4\u56f2\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isByteLength({ min:0, max:5 })<\/strong><\/pre>\n<p>\u203b \u3064\u307e\u308a\u3053\u306e\u4f8b\u306e\u5834\u5408\u300c<strong>12345<\/strong>\u300d\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u304c\u3001\u300c<strong>\u306d\u3053<\/strong>\u300d\u306f\u901a\u904e\u3057\u307e\u305b\u3093\u3002\u306a\u305c\u306a\u3089<code>UTF-8<\/code>\u306f<code>3<\/code>\u30d0\u30a4\u30c8\u6587\u5b57\u306a\u306e\u3067\u3001\u9577\u3055\u304c<code>6<\/code>\u306b\u306a\u308b\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u203b\u3082\u3057\u5358\u7d14\u306b\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u30c1\u30a7\u30c3\u30af\u3057\u305f\u3044\u5834\u5408\u306f<a href=\"#isLength\">isLength()<\/a>\u3092\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u756a\u53f7\u304b\u3069\u3046\u304b\uff1a isCreditCard()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u5165\u529b\u3055\u308c\u305f\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u756a\u53f7\u304c\u6b63\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002\uff08\u203b \u305f\u3060\u3057\u3001\u3042\u304f\u307e\u3067\u6587\u5b57\u5217\u304c\u6b63\u3057\u3044\u304b\u306e\u30c1\u30a7\u30c3\u30af\u3067\u3059\u3002\u5b9f\u969b\u306b\u30ab\u30fc\u30c9\u756a\u53f7\u304c\u6709\u52b9\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n<pre>check('attribute_name').<strong>isCreditCard()<\/strong><\/pre>\n<h2>\u91d1\u984d\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isCurrency()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u00a51,000\u300d\u3068\u3044\u3046\u6587\u5b57\u5217\u304c\u91d1\u984d\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name')\r\n  .<strong>isCurrency({<\/strong>\r\n    \/\/ \u4efb\u610f<strong>\r\n    symbol: '\u00a5',  \/\/ \u901a\u8ca8\u30b7\u30f3\u30dc\u30eb\r\n    require_symbol: false,  \/\/ \u901a\u8ca8\u30b7\u30f3\u30dc\u30eb\uff08$, \u00a5\uff09\u306a\u3069\u304c\u5fc5\u8981\uff1f\r\n    allow_negatives: true,  \/\/ \u30de\u30a4\u30ca\u30b9\u306e\u6570\u5b57\u306fOK\uff1f\r\n    allow_decimal: false,   \/\/ \u5c0f\u6570\u70b9OK\uff1f\r\n  })<\/strong><\/pre>\n<p>\u203b \u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u3001\u65e5\u672c\u74b0\u5883\u306b\u5408\u3046\u3082\u306e\u3092\u30d4\u30c3\u30af\u30a2\u30c3\u30d7\u3057\u307e\u3057\u305f\u3002\u305d\u306e\u4ed6\u306e\u3082\u306e\u306f<a href=\"https:\/\/github.com\/validatorjs\/validator.js\/blob\/master\/README.md\" target=\"_blank\" rel=\"noopener noreferrer\">\u3053\u3061\u3089<\/a>\u3067\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>dataURI\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isDataURI()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001<code>dataURI<\/code>\u306b\u5909\u63db\u3055\u308c\u305f\u753b\u50cf\u30c7\u30fc\u30bf\u304c\u6b63\u3057\u3044\u5f62\u5f0f\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>check('attribute_name').isDataURI()<\/strong><\/pre>\n<h2>\u6570\u5b57\u304b\u3069\u3046\u304b\uff1a isNumeric()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c<strong>-10<\/strong>\u300d\u300c<strong>1.5<\/strong>\u300d\u300c<strong>3<\/strong>\u300d\u306a\u3069\u306e\u6570\u5024\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isNumeric()<\/strong><\/pre>\n<h2>Int\u578b\u306e\u6570\u5b57\u304b\u3069\u3046\u304b\uff1a isInt()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u6574\u6570\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name')\r\n  <strong>.isInt({\r\n<\/strong>    \/\/ \u4efb\u610f<strong>\r\n    min: 3,\r\n    max: 10\r\n  })<\/strong><\/pre>\n<p>\u203b\u3053\u306e\u4f8b\u3067\u306f\u3001\u5165\u529b\u5024\u304c<code>3<\/code>\u3001\u3082\u3057\u304f\u306f<code>10<\/code>\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>Float\u578b\u306e\u6570\u5b57\u304b\u3069\u3046\u304b\uff1a isFloat()<\/h2>\n<pre>check('attribute_name')\r\n  <strong>.isFloat({\r\n<\/strong>    \/\/ \u4efb\u610f<strong>\r\n    min: 1.2,\r\n    max: 5.8\r\n  })<\/strong><\/pre>\n<p>\u203b\u3053\u306e\u4f8b\u306e\u5834\u5408\u3001<code>1.2<\/code>\u3068<code>5.8<\/code>\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>Decimal\u578b\u306e\u6570\u5b57\u304b\u3069\u3046\u304b\uff1a isDecimal()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u91ce\u7403\u3067\u8a00\u3046\u9632\u5fa1\u7387\uff08\u4f8b\uff1a<code>2.59<\/code>\uff09\u306a\u3069\u5c0f\u6570\u70b9\u3064\u304d\u306e\u6570\u5b57\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name')\r\n  <strong>.isDecimal({\r\n<\/strong>    \/\/ \u4efb\u610f<strong>\r\n    force_decimal: false,<\/strong> \/\/ \u5c0f\u6570\u70b9\u304c\u306a\u3044\u6570\u5b57\u3082OK\u306a\u5834\u5408<strong>\r\n    decimal_digits: '2'  <\/strong>\/\/ \u5c0f\u6570\u70b9\u4ee5\u4e0b\u304c\uff12\u6841\u3067\u56fa\u5b9a<strong>\r\n  })<\/strong><\/pre>\n<p>\u203b\u3082\u3057\u5c0f\u6570\u70b9\u4ee5\u4e0b\u304c\uff11\u6841\u4ee5\u4e0a\u3001\uff12\u6841\u4ee5\u4e0b\u306b\u3059\u308b\u5834\u5408\u306f\u3001<code>1,2<\/code>\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u7279\u5b9a\u306e\u6570\u5b57\u3067\u5272\u308a\u5207\u308c\u308b\u304b\u3069\u3046\u304b\uff1a isDivisibleBy()<\/h2>\n<pre>check('attribute_name').<strong>isDivisibleBy(3)<\/strong><\/pre>\n<p>\u203b\u3053\u306e\u4f8b\u3067\u306f\u3001<code>9<\/code>\u306a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u3001<code>8<\/code>\u306a\u3089\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u304b\u3069\u3046\u304b\uff1a isEmail()<\/h2>\n<pre>check('attribute_name').<strong>isEmail()<\/strong><\/pre>\n<h2>\u7a7a\u767d\u304b\u3069\u3046\u304b\uff1a isEmpty()<\/h2>\n<pre>check('attribute_name')\r\n  <strong>.isEmpty({\r\n<\/strong>    \/\/ \u4efb\u610f<strong>\r\n    ignore_whitespace: false \/\/ \u7a7a\u767d\u3082\uff11\u6587\u5b57\u3068\u3059\u308b\r\n  })<\/strong><\/pre>\n<p>\u203b \u5168\u89d2\u6587\u5b57\u306e\u30b9\u30da\u30fc\u30b9\u3082\u5bfe\u8c61\u306b\u306a\u3063\u3066\u3044\u307e\u3059<\/p>\n<h2>\u30c9\u30e1\u30a4\u30f3\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isFQDN()<\/h2>\n<pre>check('attribute_name').<strong>isFQDN()<\/strong><\/pre>\n<h2>\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\uff1a isMultibyte()<\/h2>\n<pre>check('attribute_name').<strong>isMultibyte()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u300c<strong>\u30e2\u30f3\u30b4\u30eb800<\/strong>\u300d\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u5168\u89d2\u6587\u5b57\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\uff1a isFullWidth()<\/h2>\n<pre>check('attribute_name').<strong>isFullWidth()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u300c<strong>\u30e2\u30f3\u30b4\u30eb800<\/strong>\u300d\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u534a\u89d2\u6587\u5b57\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\uff1a isHalfWidth()<\/h2>\n<pre>check('attribute_name').<strong>isHalfWidth()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u300c<strong>\u30e2\u30f3\u30b4\u30eb800<\/strong>\u300d\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u5168\u89d2\u6587\u5b57\u3068\u534a\u89d2\u6587\u5b57\u304c\u4e21\u65b9\u542b\u307e\u308c\u3066\u3044\u308b\u304b\uff1a isVariableWidth()<\/h2>\n<pre>check('attribute_name').<strong>isVariableWidth()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u3001\u300c<strong>\u30e2\u30f3\u30b4\u30eb<\/strong>\u300d\u300c<strong>800<\/strong>\u300d\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3067\u304d\u307e\u305b\u3093\u304c\u3001\u300c<strong>\u30e2\u30f3\u30b4\u30eb800<\/strong>\u300d\u306a\u3089\u901a\u904e\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2 id=\"isHash\">\u30cf\u30c3\u30b7\u30e5\u5024\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isHash()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001<code>md5<\/code>\u306e\u30cf\u30c3\u30b7\u30e5\u5024\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isHash('md5')<\/strong><\/pre>\n<p>\u4f7f\u3048\u308b\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>md4<\/li>\n<li>md5\u3000\u30fb\u30fb\u30fb\u3000<a href=\"#isMD5\">isMD5()<\/a>\u3068\u3044\u3046\u5c02\u7528\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059<\/li>\n<li>sha1<\/li>\n<li>sha256<\/li>\n<li>sha384<\/li>\n<li>sha512<\/li>\n<li>ripemd128<\/li>\n<li>ripemd160<\/li>\n<li>tiger128<\/li>\n<li>tiger160<\/li>\n<li>tiger192<\/li>\n<li>crc32<\/li>\n<li>crc32b<\/li>\n<\/ul>\n<h2 id=\"isMD5\">MD5\u306e\u30cf\u30c3\u30b7\u30e5\u5024\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isMD5()<\/h2>\n<pre>check('attribute_name').<strong>isMD5()<\/strong><\/pre>\n<p>\u203b\u305d\u306e\u4ed6\u306e\u30cf\u30c3\u30b7\u30e5\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u306f\u3001<a href=\"#isHash\">isHash<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>16\u9032\u6570\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isHexadecimal()<\/h2>\n<pre>check('attribute_name').<strong>isHexadecimal()<\/strong><\/pre>\n<h2>\u8272\uff0816\u9032\u6570\uff09\u3068\u3057\u3066\u6b63\u3057\u3044\u304b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300c<strong>fff<\/strong>\u300d\u3084\u300c<strong>ff0000<\/strong>\u300d\u306a\u306916\u9032\u6570\u3092\u4f7f\u3063\u305f\u8272\u306e\u8868\u73fe\u304c\u6b63\u3057\u3044\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isHexColor()<\/strong><\/pre>\n<h2>\u7279\u5b9a\u306e\u5024\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\uff1a isIn()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u5165\u529b\u5024\u304c\u90fd\u9053\u5e9c\u770c\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name')\r\n  .<strong>isIn([\r\n    '\u5317\u6d77\u9053', <\/strong>\/* \uff08..\u7701\u7565\uff09 *\/<strong> '\u6c96\u7e04\u770c'\r\n  ])<\/strong><\/pre>\n<h2>\u7279\u5b9a\u306e\u5024\u3060\u3051\u3067\u69cb\u6210\u3055\u308c\u305f\u6587\u5b57\u5217\u304b\u3069\u3046\u304b\uff1a isWhitelisted()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001<code>1\u301c5<\/code>\u306e\u6570\u5b57\u306e\u307f\u3067\u69cb\u6210\u3055\u308c\u305f\u6587\u5b57\u5316\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isWhitelisted(['1', '2', '3', '4', '5'])<\/strong><\/pre>\n<p>\u203b\u3053\u306e\u4f8b\u3067\u306f\u3001\u300c<strong>12345<\/strong>\u300d\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u304c\u3001\u300c<strong>123456<\/strong>\u300d\u306f\u901a\u904e\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<h2>IP\u30a2\u30c9\u30ec\u30b9\u304b\u3069\u3046\u304b\uff1a isIP()<\/h2>\n<pre>check('attribute_name').<strong>isIP()<\/strong><\/pre>\n<p>\u203b IP\u30a2\u30c9\u30ec\u30b9<code>v4<\/code>\u3068<code>v6<\/code>\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>IP\u30a2\u30c9\u30ec\u30b9\u304c\u7bc4\u56f2\u5185\u306b\u5165\u3063\u3066\u3044\u308b\u304b\uff1a isIPRange()<\/h2>\n<p>\u4f8b\u3048\u3070\u300c10.0.0.0\/24\u300d\u306e\u3088\u3046\u306aIP\u30a2\u30c9\u30ec\u30b9\u60c5\u5831\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002\uff08v4\u306e\u307f\uff09<\/p>\n<pre>check('attribute_name').<strong>isIPRange()<\/strong><\/pre>\n<h2>ISBN\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1aisISBN<\/h2>\n<pre>check('attribute_name').<strong>isISBN()<\/strong><\/pre>\n<p>\u203b\u7b2c1\u5f15\u6570\u306b\u6841\u6570\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<code>10<\/code>\u3068<code>13<\/code>\u304c\u6709\u52b9\u3002\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306f\u4e21\u65b9\u304c\u6709\u52b9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u8a3c\u5238\u30b3\u30fc\u30c9\uff08ISIN\uff09\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isISIN()<\/h2>\n<pre>check('attribute_name').<strong>isISIN()<\/strong><\/pre>\n<h2>\u56fd\u30b3\u30fc\u30c9\uff082\u6841\uff09\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isISO31661Alpha2()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300cJP\u300d\u306a\u3069\u306e2\u6841\u306e\u56fd\u30b3\u30fc\u30c9\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isISO31661Alpha2()<\/strong><\/pre>\n<h2>\u56fd\u30b3\u30fc\u30c9\uff083\u6841\uff09\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isISO31661Alpha3()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u300cJPN\u300d\u306a\u3069\u306e3\u6841\u306e\u56fd\u30b3\u30fc\u30c9\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isISO31661Alpha3()<\/strong><\/pre>\n<h2>\u65e5\u4ed8\u3068\u3057\u3066\u6b63\u3057\u3044\u304b<\/h2>\n<pre>check('attribute_name')\r\n  .<strong>custom(value =&gt; {\r\n\r\n    const matches = value.match(\/^(\\d{4})\\\/(\\d{2})\\\/(\\d{2})$\/);\r\n    const dt = new Date(value);\r\n\r\n    if(!matches || isNaN(dt)) {\r\n\r\n      throw new Error('\u300cYYYY\/MM\/DD\u300d\u306e\u6b63\u3057\u3044\u65e5\u4ed8\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002');\r\n\r\n    }\r\n\r\n    return true;\r\n\r\n  })<\/strong><\/pre>\n<p>\u203b\u904e\u53bb\u306b<code>validator.js<\/code>\u306b\u306f<code>isDate()<\/code>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u3063\u305f\u3088\u3046\u3067\u3059\u304c\u3001\u73fe\u5728\u306f\u524a\u9664\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u72ec\u81ea\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2>\u65e5\u6642\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isISO8601()<\/h2>\n<p><code>ISO 8601<\/code>\u3067\u5b9a\u3081\u3089\u308c\u305f\u65e5\u4ed8\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isISO8601()<\/strong><\/pre>\n<p>\u306a\u304a\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3059\u308b\u4f8b\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>2000-12-15<\/li>\n<li>2000-12-15T13:50:40<\/li>\n<li>2000-12-15T13:50:40+09:00<\/li>\n<\/ul>\n<h2>\u65e5\u6642\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isRFC3339()<\/h2>\n<p><code>RFC 3339<\/code>\u3067\u5b9a\u3081\u3089\u308c\u305f\u65e5\u4ed8\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isRFC3339()<\/strong><\/pre>\n<p>\u203b\u3053\u306e\u4f8b\u3067\u306f\u3001\u300c<strong>2000-12-15T13:50:40+09:00<\/strong>\u300d\u306e\u3088\u3046\u306a\u5024\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u56fd\u969b\u6a19\u6e96\u56f3\u66f8\u756a\u53f7\uff08ISSN\uff09\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isISSN()<\/h2>\n<pre>check('attribute_name').<strong>isISSN()<\/strong><\/pre>\n<h2>\u56fd\u969b\u6a19\u6e96\u30ec\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u30b3\u30fc\u30c9\uff08ISRC\uff09\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isISRC()<\/h2>\n<pre>check('attribute_name').<strong>isISRC()<\/strong><\/pre>\n<h2>JSON\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isJSON()<\/h2>\n<pre>check('attribute_name').<strong>isJSON()<\/strong><\/pre>\n<h2>JWT\u30c8\u30fc\u30af\u30f3\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isJWT()<\/h2>\n<pre>check('attribute_name').<strong>isJWT()<\/strong><\/pre>\n<h2>\u7def\u5ea6\u7d4c\u5ea6\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isLatLong()<\/h2>\n<pre>check('attribute_name').<strong>isLatLong()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u3001\u6771\u4eac\u30b9\u30ab\u30a4\u30c4\u30ea\u30fc\u3067\u306f\u300c<strong>35.7101, 139.8107<\/strong>\u300d\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u306e\u5c0f\u6587\u5b57\u304b\u3069\u3046\u304b\uff1a isLowercase()<\/h2>\n<pre>check('attribute_name').<strong>isLowercase()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u3001<code>g<\/code>\u3084<code>j<\/code>\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002\u5168\u89d2\u6587\u5b57\u3082\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u306e\u5927\u6587\u5b57\u304b\u3069\u3046\u304b\uff1a isUppercase()<\/h2>\n<pre>check('attribute_name').<strong>isUppercase()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u3001<code>G<\/code>\u3084<code>J<\/code>\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002\u5168\u89d2\u6587\u5b57\u3082\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>MAC\u30a2\u30c9\u30ec\u30b9\u304b\u3069\u3046\u304b\uff1a isMACAddress()<\/h2>\n<pre>check('attribute_name').<strong>isMACAddress()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u3001<code>00:1B:44:11:3A:B7<\/code>\u306a\u3069\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30de\u30b0\u30cd\u30c3\u30c8\u30ea\u30f3\u30af\u304b\u3069\u3046\u304b\uff1a isMagnetURI()<\/h2>\n<pre>check('attribute_name').<strong>isMagnetURI()<\/strong><\/pre>\n<h2>MimeType\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isMimeType()<\/h2>\n<pre>check('attribute_name').<strong>isMimeType()<\/strong><\/pre>\n<h2>\u643a\u5e2f\u96fb\u8a71\u756a\u53f7\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isMobilePhone()<\/h2>\n<pre>check('attribute_name')\r\n  <strong>.isMobilePhone('ja-JP', {\r\n    strictMode: false <\/strong>\/\/ \u56fd\u969b\u96fb\u8a71\u5f62\u5f0f\u306b\u3059\u308b\u304b\u3069\u3046\u304b<strong>\r\n  })<\/strong><\/pre>\n<p>\u203b <code>strictMode<\/code>\u3092<code>true<\/code>\u306b\u3057\u305f\u5834\u5408\u3001\u4f8b\u3048\u3070\u300c<strong>+819012345678<\/strong>\u300d\u3068\u3044\u3046\u3088\u3046\u306a\u5f62\u5f0f\u306e\u307f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>MongoDB\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8ID\u304b\u3069\u3046\u304b\uff1a isMongoId()<\/h2>\n<pre>check('attribute_name').<strong>isMongoId()<\/strong><\/pre>\n<p>\u203b\u4f8b\u3048\u3070\u300c<strong>507f191e810c19729de860ea<\/strong>\u300d\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u901a\u904e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30dd\u30fc\u30c8\u756a\u53f7\u3068\u3057\u3066\u6b63\u3057\u3044\u304b\uff1a isPort()<\/h2>\n<p><code>0\u301c65535<\/code>\u306e\u6570\u5b57\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>check('attribute_name').<strong>isPort()<\/strong><\/pre>\n<h2>\u90f5\u4fbf\u756a\u53f7\u304b\u3069\u3046\u304b\uff1a isPostalCode()<\/h2>\n<pre>check('attribute_name').<strong>isPostalCode('JP')<\/strong><\/pre>\n<p>\u203b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3059\u308b\u4f8b\u3068\u3057\u3066\u306f\u3001\u300c<strong>131-0045<\/strong>\u300d\u3068\u306a\u308a\u3001<strong>\u30cf\u30a4\u30d5\u30f3\u304c\u5fc5\u8981<\/strong>\u3067\u3059\u3002<\/p>\n<h2>\u30b5\u30ed\u30b2\u30fc\u30c8\u30da\u30a2\u304b\u3069\u3046\u304b\uff1a isSurrogatePair()<\/h2>\n<pre>check('attribute_name').<strong>isSurrogatePair()<\/strong><\/pre>\n<h2>URL\u304b\u3069\u3046\u304b\uff1a isURL()<\/h2>\n<pre>check('attribute_name')\r\n  .<strong>isURL({\r\n    <\/strong>\/\/ \u4efb\u610f<strong>\r\n    protocols: ['http','https','ftp'],  \/\/ \u3069\u306e\u30d7\u30ed\u30c8\u30b3\u30eb\u304c\u6709\u52b9\uff1f\r\n    require_protocol: false,  \/\/ \u30d7\u30ed\u30c8\u30b3\u30eb\u306f\u5fc5\u8981\uff1f\r\n  })<\/strong><\/pre>\n<h2>UUID\u304b\u3069\u3046\u304b\uff1a isUUID()<\/h2>\n<pre>check('attribute_name').<strong>isUUID()<\/strong><\/pre>\n<p>\u203b \u5f15\u6570\u306b<code>UUID<\/code>\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<code>3<\/code>, <code>4<\/code>, <code>5<\/code>\u304c\u6709\u52b9\u3067\u3059\u3002<\/p>\n<h2>\u6b63\u898f\u8868\u73fe\u306b\u30de\u30c3\u30c1\u3059\u308b\u304b\uff1a matches()<\/h2>\n<pre>check('attribute_name').<strong>matches('^[a-z]+$', 'i')<\/strong><\/pre>\n<p>\u203b\u3053\u306e\u4f8b\u3067\u306f\u3001\u300c<strong>abcD<\/strong>\u300d\u306a\u3069\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u901a\u904e\u3057\u307e\u3059\u304c\u3001\u300c<strong>a3b<\/strong>\u300d\u306a\u3069\u306f\u901a\u904e\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u203b\u7b2c2\u5f15\u6570\u306f<code>modifier<\/code>\u3067\u3001\u4efb\u610f\u3067\u3059\u3002<\/p>\n<h1>\u72ec\u81ea\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u4f7f\u3046<\/h1>\n<p>\u72ec\u81ea\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u4f7f\u3046\u306b\u306f\u3001<code>withMessage()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre>check('value')\r\n  .not().isEmpty().<strong>withMessage('\u3053\u306e\u9805\u76ee\u306f\u5fc5\u9808\u5165\u529b\u3067\u3059\u3002')<\/strong>\r\n  .isEmail().<strong>withMessage('\u6709\u52b9\u306a\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002')<\/strong><\/pre>\n<p>\u305f\u3060\u3057\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u3044\u304f\u3064\u3082\u5fc5\u8981\u306b\u306a\u308b\u5834\u5408\u3001\u540c\u3058\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u4f55\u5ea6\u3082\u30bb\u30c3\u30c8\u3059\u308b\u306e\u306f\u3081\u3093\u3069\u3046\u3067\u3059\u3057\u3001\u4fdd\u5b88\u7ba1\u7406\u306b\u3082\u5411\u3044\u3066\u3044\u308b\u3068\u306f\u3044\u3048\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u305d\u3093\u306a\u5834\u5408\u306f<code>i18n<\/code>\u306a\u3069\u306e\u7ffb\u8a33\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3046\u4fbf\u5229\u3067\u3059\u3002<br \/>\n\u3084\u308a\u65b9\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<p>\u307e\u305a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>npm install --save i18n<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u81ea\u52d5\u3067\u300c<strong>locales<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u3001\u305d\u3057\u3066\u305d\u306e\u4e2d\u306b\uff08\u74b0\u5883\u306b\u3088\u3063\u3066\u9055\u3046\u3068\u601d\u3044\u307e\u3059\u304c\uff09\u300c<strong>en.json<\/strong>\u300d\u3068\u300c<strong>ja.json<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u300c<strong>app.js<\/strong>\u300d\u3092\u958b\u3044\u3066<code>i18n<\/code>\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>const i18n = require('i18n');<\/strong>\r\n\r\n\/\/ \u7ffb\u8a33\r\n<strong>app.use(i18n.init);<\/strong>\r\n<strong>i18n.configure({<\/strong>\r\n<strong>    locales:['ja'],<\/strong>\r\n<strong>    directory: __dirname + '\/locales',<\/strong>\r\n<strong>    objectNotation: true<\/strong>\r\n<strong>});<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001<code>i18n<\/code>\u306e\u6e96\u5099\u306f\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u65e5\u672c\u8a9e\u306e\u307f\u306b\u5bfe\u5fdc\u3055\u305b\u307e\u3059\u306e\u3067\u3001\u300c<strong>locales\/ja.json<\/strong>\u300d\u3092\u958b\u3044\u3066\u6b21\u306e\u3088\u3046\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>{\r\n  \"validation\": {\r\n    \"message\": {\r\n      \"required\": \"\u3053\u306e\u9805\u76ee\u306f\u5fc5\u9808\u5165\u529b\u3067\u3059\u3002\"\r\n    }\r\n  }\r\n}<\/strong><\/pre>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>check('value')\r\n  .not().isEmpty()<strong>.withMessage((value, { req }) =&gt; {\r\n\r\n    return req.__('validation.message.required');\r\n\r\n  })<\/strong><\/pre>\n<p>\u307e\u305f\u3001<code>custom()<\/code>\u3092\u4f7f\u3063\u305f\u5834\u5408\u3082\u540c\u69d8\u3067\u3059\u3002<\/p>\n<pre>check('value')\r\n  .custom((value, <strong>{ req }<\/strong>) =&gt; {\r\n\r\n    return User.count({\r\n      where: {\r\n        email: value\r\n      }\r\n    }).then(userCount =&gt; {\r\n\r\n      if(userCount &gt; 0) {\r\n\r\n        <strong>throw new Error(req.__('validation.message.email_exists'));<\/strong>\r\n\r\n      }\r\n\r\n    });\r\n\r\n  })\r\n<\/pre>\n<p>\u3053\u306e\u65b9\u6cd5\u3067<code>email<\/code>\u3084<code>unique<\/code>\u306a\u3069\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8ffd\u52a0\u3057\u3066\u4f7f\u3046\u3068\u3001\u4eca\u5f8c\u306e\u4fdd\u5b88\u7ba1\u7406\u3082\u3057\u3084\u3059\u304f\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u203b \u3061\u306a\u307f\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u5185\u5bb9\u306f\u3001<a href=\"https:\/\/github.com\/caouecs\/Laravel-lang\/blob\/master\/src\/ja\/validation.php\" target=\"_blank\" rel=\"noopener noreferrer\">Laravel-lang\u306e\u3082\u306e<\/a>\u3092\u53c2\u8003\u306b\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h1>\u72ec\u81ea\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u3046<\/h1>\n<p>\u72ec\u81ea\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u3046\u5834\u5408\u306f\u3001<code>custom()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u9001\u4fe1\u3055\u308c\u305f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u304c\u3059\u3067\u306b<code>Users<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u767b\u9332\u6e08\u307f\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>check('email').<strong>custom(value =&gt; {\r\n\r\n  return User.count({\r\n    where: {\r\n      email: value\r\n    }\r\n  }).then(userCount =&gt; {\r\n\r\n    if(userCount &gt; 0) {\r\n\r\n      throw new Error('\u3053\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306f\u3059\u3067\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u307e\u3059\u3002');\r\n\r\n    }\r\n\r\n  });\r\n\r\n})<\/strong><\/pre>\n<p>\u3053\u3053\u3067\u91cd\u8981\u306a\u306e\u304c\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306f<code>new Error('******')<\/code>\u3092\u4f7f\u3046\u90e8\u5206\u3067\u3059\u3002\u3053\u3053\u3067\u8a2d\u5b9a\u3057\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u3057\u3066\u8fd4\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u306a\u304a\u3001<code>return Promise.reject('******');<\/code>\u3067\u3082\u540c\u3058\u7d50\u679c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u300c<strong>express-validator<\/strong>\u300d\u3067<code>Express<\/code>\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u3092\u3064\u3051\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u666e\u6bb5\u304b\u3089\u3088\u304f<code>Laravel<\/code>\u3092\u4f7f\u3046\u8eab\u304b\u3089\u3059\u308b\u3068\u3001\u300c<strong>\u3078\u3047\u3001\u3053\u3093\u306a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u307e\u3067\u7528\u610f\u3057\u3066\u308b\u3093\u3060<\/strong>\u300d\u3068\u3044\u3046\u3082\u306e\u3082\u3042\u308c\u3070\u3001\u9006\u306b\u300c<strong>\u3042\u30fc\u3001\u3042\u308c\u304c\u306a\u3044\u306e\u304b<\/strong>\u300d\u306a\u3069\u3044\u3044\u90e8\u5206\u3082\u305d\u3046\u3067\u306a\u3044\u90e8\u5206\u3082\u3042\u308b\u3088\u3046\u3067\u3057\u305f\u3002<\/p>\n<p>\u3084\u306f\u308a\u4e00\u53e3\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u8a00\u3063\u3066\u3082\u3044\u308d\u3044\u308d\u3068\u9055\u3046\u90e8\u5206\u304c\u3042\u3063\u3066\u3001\u3068\u3066\u3082\u52c9\u5f37\u306b\u306a\u308a\u307e\u3059\u306d\ud83d\ude0a\u2728<\/p>\n<p>\u300c<strong>\u5225\u306e\u8a00\u8a9e\u3092\u52c9\u5f37\u3059\u308b\u306e\u306f\u3001\u30e1\u30a4\u30f3\u3067\u4f7f\u3046\u8a00\u8a9e\u306e\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u306b\u3082\u306a\u308b<\/strong>\u300d\u3068\u805e\u3044\u305f\u3053\u3068\u3092\u601d\u3044\u51fa\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u8272\u3005\u3068\u6311\u6226\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2597 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png\" alt=\"\" width=\"275\" height=\"350\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png 275w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2-236x300.png 236w\" sizes=\"auto, (max-width: 275px) 100vw, 275px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u3053\u6570\u56de\u306f\u9ad8\u901f\u306a\u30b5\u30a4\u30c8\u3092\u69cb\u7bc9\u3059\u308b\u6d41\u308c\u3067Node.js\u306eExpress\u3092\u4f7f\u3063\u305f\u958b\u767a\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3059\u3002 Express\u306fLaravel\u3068\u6bd4\u3079\u308b\u3068\u3001\u3088\u308a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=5619\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u5b9f\u4f8b\u30fb\u516861\u4ef6\uff01Express\u3067\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3059\u308b\u300cexpress-validator\u300d&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":5650,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[201,203],"tags":[5],"class_list":["post-5619","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-express","category-node-js","tag-5"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5619"}],"version-history":[{"count":29,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5619\/revisions"}],"predecessor-version":[{"id":5654,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5619\/revisions\/5654"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/5650"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}