{"id":458593,"date":"2025-05-05T15:00:40","date_gmt":"2025-05-05T15:00:40","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=458593"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=458593","title":{"rendered":"<span>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Constraint Validation API<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>DOM \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Guides\/Constraint_validation\" rel=\"noopener noreferrer nofollow\">API \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/a> \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0430. \u0412\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043c\u044b \u0438\u043c \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0447\u0430\u0441\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"xml\">&lt;input type=\"email\" required \/&gt;<\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0df\/3ff\/f6e\/0df3fff6ebc3274fe4bb0852648f68a3.gif\" alt=\"\u0416\u0438\u0432\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: https:\/\/codepen.io\/s5604\/pen\/NPPYGYj\" title=\"\u0416\u0438\u0432\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: https:\/\/codepen.io\/s5604\/pen\/NPPYGYj\" width=\"800\" height=\"268\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0df\/3ff\/f6e\/0df3fff6ebc3274fe4bb0852648f68a3.gif 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0df\/3ff\/f6e\/0df3fff6ebc3274fe4bb0852648f68a3.gif 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0416\u0438\u0432\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/codepen.io\/s5604\/pen\/NPPYGYj\" rel=\"noopener noreferrer nofollow\">https:\/\/codepen.io\/s5604\/pen\/NPPYGYj<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0430 (<code>&lt;form&gt;<\/code>) \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0432\u0432\u043e\u0434\u0430, \u0442\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u00a0<code>submit<\/code>\u00a0\u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0435\u0451, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445. \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0444\u043e\u0440\u043c\u044b (<code>submit<\/code>) \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c\u0438.<\/p>\n<p>\u041e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 (\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e) \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u00a0<code>novalidate<\/code>. \u0415\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043a \u0442\u0435\u0433\u0443\u00a0<code>&lt;form&gt;<\/code>, \u044d\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0432\u0441\u0435\u0439 \u0444\u043e\u0440\u043c\u044b. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f.<\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u00a0<code>type<\/code>. \u041f\u043e\u043b\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Guides\/Constraint_validation#validation-related_attributes\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/a>.<\/p>\n<p><strong>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u044f\u0437\u044b\u043a\u0435, \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0438 \u0438\u043c\u0435\u044e\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043d\u0435 \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043b\u0430\u0441\u0441\u044b <code>:invalid<\/code>, <code>:out-of-range<\/code>, <code>:empty<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 (accessibility) \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 <\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u043c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 (\u044d\u0442\u0438\u043c \u043c\u044b \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043f\u043e\u0437\u0436\u0435).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u043b\u044c\u0437\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0421 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439 (\u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e) \u043d\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0433\u043b\u0430\u0434\u043a\u043e<em>.<\/em><\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b. <\/p>\n<p><strong>\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0444\u043e\u0440\u043c\u0435<\/strong><\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u0432\u044b\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0435 \u043e\u043f\u043b\u0430\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u044f\u0442\u044c \u043f\u043e\u043b\u0435\u0439: <\/p>\n<ol>\n<li>\n<p><strong>\u0415\u043c\u044d\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0447\u0435\u043a\u0430<\/strong>. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0432\u0438\u0434\u0430\u00a0<code>@habr.com<\/code><\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u044b\u0431\u043e\u0440 \u0432\u0430\u043b\u044e\u0442\u044b<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0443\u043c\u043c\u0430 \u043f\u043b\u0430\u0442\u0435\u0436\u0430. <\/strong>\u0411\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442<\/p>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041f\u0430\u0440\u043e\u043b\u044c<\/strong><\/p>\n<ul>\n<li>\n<p>\u0434\u043b\u0438\u043d\u0430 \u043e\u0442 5 \u0434\u043e 12 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b \u0440\u0443\u0431\u043b\u044f (\u20bd), \u0435\u0441\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u0432\u0430\u043b\u044e\u0442\u0430 &#171;\u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0439 \u0440\u0443\u0431\u043b\u044c&#187;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b \u0434\u043e\u043b\u043b\u0430\u0440\u0430 ($) \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0430\u043b\u044e\u0442<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440 \u043f\u0430\u0440\u043e\u043b\u044f. \u0414\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u043e\u043b\u0435\u043c.<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"javascript\">const CurrenciesEnum = {   RUR: 'RUR',   USD: 'USD' }  const Currencies = Object.keys(CurrenciesEnum);  const MIN_RUR_SUM = 1000 const MAX_RUR_SUM = 150000  const MIN_USD_SUM = 100 const MAX_USD_SUM = 5000<\/code><\/pre>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"javascript\">class PaymentForm {   \/\/ \u0442\u0443\u0442 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0448\u0438\u0431\u043a\u0430\u0445,   \/\/ \u043a\u0430\u043a \u043f\u0430\u0440\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e =&gt; \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438   errors = new Map;      email = '';   currency = CurrenciesEnum.RUR;   sum = '';   password = '';   passwordCopy = '';    \/\/ \u0432\u0435\u0440\u043d\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043e\u043f\u043b\u0430\u0442\u044b \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442,    \/\/ \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b   get minSum() {     const hour = new Date().getHours()     switch (this.currency) {       case 'RUR':         return hour &gt; 12 ? MIN_RUR_SUM : MIN_RUR_SUM + 500;       case 'USD':         return hour &gt; 12 ? MIN_USD_SUM : MIN_USD_SUM + 5;       default:         return 0     }   }    \/\/ \u0432\u0435\u0440\u043d\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043e\u043f\u043b\u0430\u0442\u044b \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u0430\u043b\u044e\u0442\u044b   get maxSum() {     switch (this.currency) {       case 'RUR':         return MAX_RUR_SUM;       case 'USD':         return MAX_USD_SUM;       default:         return Number.MAX_VALUE     }   }    \/\/ \u0432\u0435\u0440\u043d\u0435\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u043b\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b   get passwordPattern() {     return `${CurrenciesSymbols[this.currency]}{1}`   }    \/\/ \u0431\u0443\u0434\u0435\u043c \u0434\u0438\u0441\u0435\u0439\u0431\u043b\u0438\u0442\u044c \u043a\u043e\u043f\u0438\u044e \u043f\u0430\u0440\u043e\u043b\u044f \u043f\u043e\u043a\u0430 \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u0435\u043d   get passwordCopyDisabled() {     return this.password === '' || this.errors.has('password');   } }<\/code><\/pre>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0420\u0430\u0437\u043c\u0435\u0447\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c react.<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"javascript\">function Form() {   return (     &lt;form&gt;       &lt;input          required         type=\"email\"          name=\"email\"          pattern='@habr.com'       \/&gt;            &lt;select name=\"currency\" value={paymentForm.currency}&gt;         {Currencies.map(currency =&gt; (           &lt;option value={currency} key={currency}&gt;             {currency}           &lt;\/option&gt;         ))}       &lt;\/select&gt;            &lt;input          value={paymentForm.sum}         min={paymentForm.minSum}         min={paymentForm.maxSum}         type=\"number\"          name=\"sum\"        \/&gt;              &lt;input          required         type=\"password\"          name=\"password\"          pattern={paymentForm.passwordPattern}         minLength=\"5\"         maxLength=\"12\"       \/&gt;            &lt;input          required         type=\"password\"          name=\"passwordCopy\"          \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0430\u043a         \/\/ \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c         pattern={paymentForm.password}         \/\/ \u0435\u0441\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u0435\u043d, \u0434\u0438\u0441\u0435\u0439\u0431\u043b\u0438\u043c \u044d\u0442\u043e \u043f\u043e\u043b\u0435         disabled={paymentForm.errors.has('password')}       \/&gt;     &lt;\/form&gt;   ) }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u0444\u043e\u0440\u043c\u0430 \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430, \u043d\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430. \u041c\u044b \u0443\u0437\u043d\u0430\u0451\u043c \u043e \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044f\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 (submit). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 FormValidator, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b<\/p>\n<\/li>\n<li>\n<p>\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/API\/HTMLInputElement\/invalid_event\" rel=\"noopener noreferrer nofollow\">invalid<\/a> \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 schema. \u042d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435  \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u0430\u043a \u0443 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/ValidityState\" rel=\"noopener noreferrer nofollow\">ValidityState<\/a> (\u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438):<\/p>\n<ul>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 valid \u0438 customError<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u043c \u0442\u0438\u043f\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 boolean \u043d\u0430 string<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0442\u0435\u043a\u0441\u0442\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u043d\u0430\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a.<\/p>\n<pre><code class=\"typescript\">type ValidationErrors = Record&lt;keyof Omit&lt;ValidityState, 'valid' | 'customError'&gt;, string&gt; type ValidationSchema = Record&lt;string, Partial&lt;ValidationErrors&gt;&gt;<\/code><\/pre>\n<p>\u041b\u043e\u0433\u0438\u043a\u0443 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043c\u044b \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 FormController, \u0430 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 API \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u0432\u0438\u0434\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <code>validate<\/code>.<\/p>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043b\u044e\u0431\u043e\u0439 HTMLElement (\u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0442\u0435\u0433\u00a0<code>&lt;form&gt;<\/code>, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 (\u044d\u0442\u043e\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0444\u043e\u0440\u043c\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442).<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"typescript\">class FormValidator {   #controller = new FormController();    constructor(schema?: ValidationSchema) {     this.#controller.schema = schema || {};   }    validate = (element: HTMLElement | null) =&gt; {     if (!element) {       this.#controller.form?.removeEventListener('change', this.#controller);       this.#controller.form?.removeEventListener('input', this.#controller)       this.#controller.form = null;     } else {       this.#controller.form = element;       element.addEventListener('change', this.#controller);       element.addEventListener('input', this.#controller)     }   }; }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c FormController. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 EventHandler, \u0432   \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 FormController \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u043c\u0435\u0442\u043e\u0434 <code>addEventListener<\/code>, \u0447\u0442\u043e \u043b\u0435\u0433\u0430\u043b\u044c\u043d\u043e )).<\/p>\n<pre><code class=\"typescript\">class FormController {   form: HTMLElement | null = null;   schema: ValidationSchema = {};   #debounce: any    handleEvent() {     clearTimeout(this.#debounce);     this.#debounce = setTimeout(this.#checkValidity, 50);   }    #checkValidity = () =&gt; {     if (!this.form) return;     this.form.querySelectorAll(\"*:invalid\")       .forEach((element: HTMLInputElement) =&gt; {         this.#setValidationMessage(element);         element.checkValidity();       });   };    #setValidationMessage(target: HTMLInputElement) {     const { validity, name } = target;     if (validity.valid) return target.setCustomValidity(\"\");      for (const type in validity) {       if (type === \"valid\" || type === \"customError\") {         target.setCustomValidity(\"\");         break;       }       if (validity[type] === true) {         const schema = this.schema[name];         if (schema) {           const message = schema[type];           if (message) {             target.setCustomValidity(message);           } else {             target.setCustomValidity(\"\");           }         } else {           target.setCustomValidity(\"\");         }         break;       }     }   } }<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<ol>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 handleEvent<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u00a0<code>input<\/code>\u00a0\u0438\u00a0<code>change<\/code><\/p>\n<\/li>\n<li>\n<p>\u0421 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u00a0<code>#checkValidity<\/code><br \/><em>\u0412 vanilla-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c, \u043d\u043e \u0432 React-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0434\u043b\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/em><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 #checkValidity<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\u00a0<code>select<\/code>\u00a0\u0438\u00a0<code>input<\/code>\u00a0\u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u043e\u0440\u043c\u044b<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u00a0<code>#setValidationMessage<\/code><\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u00a0<code>checkValidity()<\/code>\u00a0\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u00a0<code>invalid<\/code><\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 #setValidationMessage<\/strong><\/p>\n<ul>\n<li>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u00a0<code>ValidityState<\/code>\u00a0\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u0445\u0435\u043c\u0435 \u0437\u0430\u0434\u0430\u043d \u0442\u0435\u043a\u0441\u0442:<\/p>\n<ul>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u043a\u0430\u043a\u00a0<code>validationMessage<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435:<\/p>\n<ul>\n<li>\n<p>\u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b \u0438 FormValidator \u0432 React \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ref<\/code>. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0445\u0435\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"javascript\">const schema = {   email: {     patternMismatch: '\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0430\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u043d\u0430 \u0445\u0430\u0431\u0440\u0435'   },   sum: {     rangeUnderflow: '\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0441\u0443\u043c\u043c\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435',     rangeOverflow: '\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0434\u0435\u043d\u0435\u0433, \u043c\u044b \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043c'   },   password: {     \/\/ \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b     get patternMismatch() {       return `\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u0438\u043c\u0432\u043e\u043b \"${paymentForm.currency}\" \u0432 \u043f\u0430\u0440\u043e\u043b\u044c, \u044d\u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e`     }   } }  const validator = new FormValidator(schema);  function Form() {   return (     &lt;form ref={validator.validate}&gt;       \/\/ ...     &lt;\/form&gt;   ) }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 PaymentForm \u043c\u0435\u0442\u043e\u0434 <code>onInvalid<\/code>.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>invalid<\/code> &#8212; \u043e\u043d\u043e \u043d\u0435 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0432\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u0432\u0432\u043e\u0434\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435 (\u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u043c\u0435\u044e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>name<\/code>) \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<pre><code class=\"javascript\">class PaymentForm {   errors = new Map;    onInvalid(event) {     this.errors.set(       event.target.name, \/\/ \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f       event.target.validationMessage \/\/ \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438     )   } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>onChange<\/code>:<\/p>\n<pre><code class=\"javascript\">class PaymentForm {    onChange(event) {     let value = event.target.value; \/\/ \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435          \/\/ valueAsNumber \u0431\u0443\u0434\u0435\u0442 NaN \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0432\u0432\u043e\u0434\u0430,      \/\/ \u0438 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u0434\u043b\u044f type number, date[-*] \u0438 range     if (!isNaN(event.target.valueAsNumber)) {       \/\/ \u0442\u0430\u043a \u0432 sum \u043c\u044b \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0447\u0438\u0441\u043b\u043e       value = event.target.valueAsNumber;     }     this[event.target.name] = value;   } }<\/code><\/pre>\n<p>\u042f \u043e\u043f\u0443\u0449\u0443 \u044d\u0442\u0430\u043f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0440\u044f\u0434\u043e\u043c \u0441 \u043f\u043e\u043b\u044f\u043c\u0438 \u0432\u0432\u043e\u0434\u0430 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 <code>change<\/code> \u0438 <code>invalid<\/code>. \u041f\u043e\u043b\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 (<a href=\"https:\/\/stackblitz.com\/edit\/vitejs-vite-xyuagd8v?file=src%2FPayment.form.ts\" rel=\"noopener noreferrer nofollow\">sandbox<\/a>).<\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u041c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0444\u043e\u0440\u043c\u044b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Constraint Validation API. \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441 \u043f\u043e\u043b\u0435\u043c \u0432\u0432\u043e\u0434\u0430, \u043d\u043e \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438. \u041e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442:<\/p>\n<ul>\n<li>\n<p>\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0432\u043e\u0434\u0435<\/p>\n<\/li>\n<li>\n<p>\u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 FormController \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 <code>checkValidity()<\/code> \u043d\u0430 <code>reportValidity()<\/code> \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>#checkValidity<\/code>.<\/p>\n<pre><code class=\"javascript\">#checkValidity = () =&gt; {   if (!this.form) return;   this.form.querySelectorAll(\"*:invalid\")     .forEach((element: HTMLInputElement) =&gt; {       this.#setValidationMessage(element);       \/\/ \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443       element.reportValidity();      }); };<\/code><\/pre>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0442\u0443\u0442: <a href=\"https:\/\/stackblitz.com\/edit\/vitejs-vite-xyuagd8v?file=src%2FPayment.form.ts\" rel=\"noopener noreferrer nofollow\">https:\/\/stackblitz.com\/edit\/vitejs-vite-xyuagd8v<\/a><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435, FormValidator \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d \u0432 <a href=\"https:\/\/www.npmjs.com\/package\/kr-form-validator\" rel=\"noopener noreferrer nofollow\">npm<\/a>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432\u0440\u0443\u0447\u043d\u0443\u044e<\/p>\n<p><strong>\u0412\u044b\u0432\u043e\u0434\u044b<\/strong><\/p>\n<p>Constraint Validation API \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043b\u043d\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445. <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/906534\/\"> https:\/\/habr.com\/ru\/articles\/906534\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>DOM \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Guides\/Constraint_validation\" rel=\"noopener noreferrer nofollow\">API \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/a> \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0430. \u0412\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043c\u044b \u0438\u043c \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0447\u0430\u0441\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"xml\">&lt;input type=\"email\" required \/&gt;<\/code><\/pre>\n<figure class=\"full-width\">\n<div><figcaption>\u0416\u0438\u0432\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/codepen.io\/s5604\/pen\/NPPYGYj\" rel=\"noopener noreferrer nofollow\">https:\/\/codepen.io\/s5604\/pen\/NPPYGYj<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0430 (<code>&lt;form&gt;<\/code>) \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0432\u0432\u043e\u0434\u0430, \u0442\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u00a0<code>submit<\/code>\u00a0\u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0435\u0451, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445. \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0444\u043e\u0440\u043c\u044b (<code>submit<\/code>) \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c\u0438.<\/p>\n<p>\u041e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 (\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e) \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u00a0<code>novalidate<\/code>. \u0415\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043a \u0442\u0435\u0433\u0443\u00a0<code>&lt;form&gt;<\/code>, \u044d\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0432\u0441\u0435\u0439 \u0444\u043e\u0440\u043c\u044b. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f.<\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u00a0<code>type<\/code>. \u041f\u043e\u043b\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Guides\/Constraint_validation#validation-related_attributes\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/a>.<\/p>\n<p><strong>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u044f\u0437\u044b\u043a\u0435, \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0438 \u0438\u043c\u0435\u044e\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043d\u0435 \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043b\u0430\u0441\u0441\u044b <code>:invalid<\/code>, <code>:out-of-range<\/code>, <code>:empty<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 (accessibility) \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 <\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u043c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 (\u044d\u0442\u0438\u043c \u043c\u044b \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043f\u043e\u0437\u0436\u0435).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u043b\u044c\u0437\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0421 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439 (\u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e) \u043d\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0433\u043b\u0430\u0434\u043a\u043e<em>.<\/em><\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b. <\/p>\n<p><strong>\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0444\u043e\u0440\u043c\u0435<\/strong><\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u0432\u044b\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0435 \u043e\u043f\u043b\u0430\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u044f\u0442\u044c \u043f\u043e\u043b\u0435\u0439: <\/p>\n<ol>\n<li>\n<p><strong>\u0415\u043c\u044d\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0447\u0435\u043a\u0430<\/strong>. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0432\u0438\u0434\u0430\u00a0<code>@habr.com<\/code><\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u044b\u0431\u043e\u0440 \u0432\u0430\u043b\u044e\u0442\u044b<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0443\u043c\u043c\u0430 \u043f\u043b\u0430\u0442\u0435\u0436\u0430. <\/strong>\u0411\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442<\/p>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041f\u0430\u0440\u043e\u043b\u044c<\/strong><\/p>\n<ul>\n<li>\n<p>\u0434\u043b\u0438\u043d\u0430 \u043e\u0442 5 \u0434\u043e 12 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b \u0440\u0443\u0431\u043b\u044f (\u20bd), \u0435\u0441\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u0432\u0430\u043b\u044e\u0442\u0430 &#171;\u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0439 \u0440\u0443\u0431\u043b\u044c&#187;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b \u0434\u043e\u043b\u043b\u0430\u0440\u0430 ($) \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0430\u043b\u044e\u0442<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440 \u043f\u0430\u0440\u043e\u043b\u044f. \u0414\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u043e\u043b\u0435\u043c.<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"javascript\">const CurrenciesEnum = {   RUR: 'RUR',   USD: 'USD' }  const Currencies = Object.keys(CurrenciesEnum);  const MIN_RUR_SUM = 1000 const MAX_RUR_SUM = 150000  const MIN_USD_SUM = 100 const MAX_USD_SUM = 5000<\/code><\/pre>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"javascript\">class PaymentForm {   \/\/ \u0442\u0443\u0442 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0448\u0438\u0431\u043a\u0430\u0445,   \/\/ \u043a\u0430\u043a \u043f\u0430\u0440\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e =&gt; \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438   errors = new Map;      email = '';   currency = CurrenciesEnum.RUR;   sum = '';   password = '';   passwordCopy = '';    \/\/ \u0432\u0435\u0440\u043d\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043e\u043f\u043b\u0430\u0442\u044b \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442,    \/\/ \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b   get minSum() {     const hour = new Date().getHours()     switch (this.currency) {       case 'RUR':         return hour &gt; 12 ? MIN_RUR_SUM : MIN_RUR_SUM + 500;       case 'USD':         return hour &gt; 12 ? MIN_USD_SUM : MIN_USD_SUM + 5;       default:         return 0     }   }    \/\/ \u0432\u0435\u0440\u043d\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043e\u043f\u043b\u0430\u0442\u044b \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u0430\u043b\u044e\u0442\u044b   get maxSum() {     switch (this.currency) {       case 'RUR':         return MAX_RUR_SUM;       case 'USD':         return MAX_USD_SUM;       default:         return Number.MAX_VALUE     }   }    \/\/ \u0432\u0435\u0440\u043d\u0435\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u043b\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u044e\u0442\u044b   get passwordPattern() {     return `${CurrenciesSymbols[this.currency]}{1}`   }    \/\/ \u0431\u0443\u0434\u0435\u043c \u0434\u0438\u0441\u0435\u0439\u0431\u043b\u0438\u0442\u044c \u043a\u043e\u043f\u0438\u044e \u043f\u0430\u0440\u043e\u043b\u044f \u043f\u043e\u043a\u0430 \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u0435\u043d   get passwordCopyDisabled() {     return this.password === '' || this.errors.has('password');   } }<\/code><\/pre>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0420\u0430\u0437\u043c\u0435\u0447\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c react.<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"javascript\">function Form() {   return (     &lt;form&gt;       &lt;input          required         type=\"email\"          name=\"email\"          pattern='@habr.com'       \/&gt;            &lt;select name=\"currency\" value={paymentForm.currency}&gt;         {Currencies.map(currency =&gt; (           &lt;option value={currency} key={currency}&gt;             {currency}           &lt;\/option&gt;         ))}       &lt;\/select&gt;            &lt;input          value={paymentForm.sum}         min={paymentForm.minSum}         min={paymentForm.maxSum}         type=\"number\"          name=\"sum\"        \/&gt;              &lt;input          required         type=\"password\"          name=\"password\"          pattern={paymentForm.passwordPattern}         minLength=\"5\"         maxLength=\"12\"       \/&gt;            &lt;input          required         type=\"password\"          name=\"passwordCopy\"          \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0430\u043a         \/\/ \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c         pattern={paymentForm.password}         \/\/ \u0435\u0441\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u0435\u043d, \u0434\u0438\u0441\u0435\u0439\u0431\u043b\u0438\u043c \u044d\u0442\u043e \u043f\u043e\u043b\u0435         disabled={paymentForm.errors.has('password')}       \/&gt;     &lt;\/form&gt;   ) }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u0444\u043e\u0440\u043c\u0430 \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430, \u043d\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430. \u041c\u044b \u0443\u0437\u043d\u0430\u0451\u043c \u043e \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044f\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 (submit). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 FormValidator, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b<\/p>\n<\/li>\n<li>\n<p>\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/API\/HTMLInputElement\/invalid_event\" rel=\"noopener noreferrer nofollow\">invalid<\/a> \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 schema. \u042d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435  \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u0430\u043a \u0443 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/ValidityState\" rel=\"noopener noreferrer nofollow\">ValidityState<\/a> (\u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438):<\/p>\n<ul>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 valid \u0438 customError<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u043c \u0442\u0438\u043f\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 boolean \u043d\u0430 string<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0442\u0435\u043a\u0441\u0442\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u043d\u0430\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a.<\/p>\n<pre><code class=\"typescript\">type ValidationErrors = Record&lt;keyof Omit&lt;ValidityState, 'valid' | 'customError'&gt;, string&gt; type ValidationSchema = Record&lt;string, Partial&lt;ValidationErrors&gt;&gt;<\/code><\/pre>\n<p>\u041b\u043e\u0433\u0438\u043a\u0443 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043c\u044b \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 FormController, \u0430 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 API \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u0432\u0438\u0434\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <code>validate<\/code>.<\/p>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043b\u044e\u0431\u043e\u0439 HTMLElement (\u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0442\u0435\u0433\u00a0<code>&lt;form&gt;<\/code>, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 (\u044d\u0442\u043e\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0444\u043e\u0440\u043c\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442).<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"typescript\">class FormValidator {   #controller = new FormController();    constructor(schema?: ValidationSchema) {     this.#controller.schema = schema || {};   }    validate = (element: HTMLElement | null) =&gt; {     if (!element) {       this.#controller.form?.removeEventListener('change', this.#controller);       this.#controller.form?.removeEventListener('input', this.#controller)       this.#controller.form = null;     } else {       this.#controller.form = element;       element.addEventListener('change', this.#controller);       element.addEventListener('input', this.#controller)     }   }; }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c FormController. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 EventHandler, \u0432   \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 FormController \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u043c\u0435\u0442\u043e\u0434 <code>addEventListener<\/code>, \u0447\u0442\u043e \u043b\u0435\u0433\u0430\u043b\u044c\u043d\u043e )).<\/p>\n<pre><code class=\"typescript\">class FormController {   form: HTMLElement | null = null;   schema: ValidationSchema = {};   #debounce: any    handleEvent() {     clearTimeout(this.#debounce);     this.#debounce = setTimeout(this.#checkValidity, 50);   }    #checkValidity = () =&gt; {     if (!this.form) return;     this.form.querySelectorAll(\"*:invalid\")       .forEach((element: HTMLInputElement) =&gt; {         this.#setValidationMessage(element);         element.checkValidity();       });   };    #setValidationMessage(target: HTMLInputElement) {     const { validity, name } = target;     if (validity.valid) return target.setCustomValidity(\"\");      for (const type in validity) {       if (type === \"valid\" || type === \"customError\") {         target.setCustomValidity(\"\");         break;       }       if (validity[type] === true) {         const schema = this.schema[name];         if (schema) {           const message = schema[type];           if (message) {             target.setCustomValidity(message);           } else {             target.setCustomValidity(\"\");           }         } else {           target.setCustomValidity(\"\");         }         break;       }     }   } }<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<ol>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 handleEvent<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u00a0<code>input<\/code>\u00a0\u0438\u00a0<code>change<\/code><\/p>\n<\/li>\n<li>\n<p>\u0421 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u00a0<code>#checkValidity<\/code><br \/><em>\u0412 vanilla-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c, \u043d\u043e \u0432 React-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0434\u043b\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/em><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 #checkValidity<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\u00a0<code>select<\/code>\u00a0\u0438\u00a0<code>input<\/code>\u00a0\u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u043e\u0440\u043c\u044b<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u00a0<code>#setValidationMessage<\/code><\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u00a0<code>checkValidity()<\/code>\u00a0\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u00a0<code>invalid<\/code><\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 #setValidationMessage<\/strong><\/p>\n<ul>\n<li>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u00a0<code>ValidityState<\/code>\u00a0\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u0445\u0435\u043c\u0435 \u0437\u0430\u0434\u0430\u043d \u0442\u0435\u043a\u0441\u0442:<\/p>\n<ul>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u043a\u0430\u043a\u00a0<code>validationMessage<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435:<\/p>\n<ul>\n<li>\n<p>\u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b \u0438 FormValidator \u0432 React \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ref<\/code>. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0445\u0435\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"javascript\">const schema = {   email: {     patternMismatch: '\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0430\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u043d\u0430 \u0445\u0430\u0431\u0440\u0435'   },   sum: {     rangeUnderflow: '\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0441\u0443\u043c\u043c\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435',     rangeOverflow: '\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0434\u0435\u043d\u0435\u0433, \u043c\u044b \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043c'   },   password: {     \/\/ \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b     get patternMismatch() {       return `\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u0438\u043c\u0432\u043e\u043b \"${paymentForm.currency}\" \u0432 \u043f\u0430\u0440\u043e\u043b\u044c, \u044d\u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e`     }   } }  const validator = new FormValidator(schema);  function Form() {   return (     &lt;form ref={validator.validate}&gt;       \/\/ ...     &lt;\/form&gt;   ) }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 PaymentForm \u043c\u0435\u0442\u043e\u0434 <code>onInvalid<\/code>.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>invalid<\/code> &#8212; \u043e\u043d\u043e \u043d\u0435 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0432\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u0432\u0432\u043e\u0434\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435 (\u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u043c\u0435\u044e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>name<\/code>) \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<pre><code class=\"javascript\">class PaymentForm {   errors = new Map;    onInvalid(event) {     this.errors.set(       event.target.name, \/\/ \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f       event.target.validationMessage \/\/ \u0442\u0435\u043a\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438     )   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-458593","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=458593"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458593\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=458593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=458593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=458593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}