{"id":184344,"date":"2013-06-23T15:33:03","date_gmt":"2013-06-23T11:33:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=184344"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=184344","title":{"rendered":"<span class=\"post_title\">CoffeeScript \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445. \u0427\u0430\u0441\u0442\u044c 1: \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435. \u0417\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043c\u044b \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0432 \u041b\u0421.<\/p>\n<p>  \u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e  <\/p>\n<ul>\n<li>\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f CoffeeScript<\/li>\n<li>\u201c\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0435\u201d \u041e\u041e\u041f \u0441 CoffeeScript<\/li>\n<li>\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0443\u0434\u0430\u0447\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/li>\n<li>jQuery \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 CoffeeScript<\/li>\n<li>\u043c\u0438\u043a\u0440\u043e\u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u043d\u0430 CoffeeScript<\/li>\n<\/ul>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u041d\u0438\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b:  <\/p>\n<ul>\n<li>\u0432\u0435\u0440\u0441\u0438\u044f \u043a\u043e\u0434\u0430 \u0431\u0435\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432<\/li>\n<li>\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438<\/li>\n<li>\u0432\u0435\u0440\u0441\u0438\u044f \u043a\u043e\u0434\u0430 \u0441 \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438<\/li>\n<li>\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/li>\n<li>\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <\/li>\n<\/ul>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 jQuery.<\/p>\n<p>  <i>\u0412 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435 \u043d\u0435\u0442 \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0438 Coffee, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0443\u044e.<\/i><\/p>\n<pre><code class=\"python\">class validation \tfind: (rules, rule) -&gt; \t\trules = rules.split '|' \t\t(rule in rules) \tvalidate: (rules) -&gt; \t\t$('.form_error').remove() \t\tdelete @errors_list \t\t@fields = {} \t\t@data = {} \t\tfor field, rule of rules \t\t\t@fields[field] = $(&quot;input[name=\\&quot;#{field}\\&quot;]&quot;); \t\t\t@data[field] = @fields[field].val() \t\t\t@validate_field field, @data[field], rules_string \t\tunless @errors_list?  \t\t\t@data \t\telse \t\t\t@show_errors() \t\t\tfalse \tshow_errors: -&gt; \t\tfocus_set = false \t\tfor field, errors of @errors_list \t\t\tmessages = [] \t\t\tfor error in errors  \t\t\t\tmessages.push @lang error \t\t\t@fields[field].before nano templates.form_error, {message: messages.join(' ')} \t\t\tunless focus_set \t\t\t\t@fields[field].focus() \t\t\t\tfocus_set = true \tlang: (error) -&gt; \t\t[rule,value] = @rule_value error \t\tif value? \t\t\tnano lang.errors[rule], {val: value}) \t\telse \t\t\tlang.errors[rule] \trule_value: (rule)-&gt; \t\tx = rule.split '[' \t\tif x[1]? \t\t\tif x[1].substr(x[1].length - 1) == ']' \t\t\t\tx[1] = x[1].substr 0, x[1].length - 1 \t\t[x[0],x[1]] \tmin_length: (str,length) -&gt; \t\t(str.length &gt;= length) \tmax_length: (str,length) -&gt; \t\t(str.length &lt; length) \tvalid_email: (str) -&gt; \t\t(\/^[\\w\\d_-]+@+[\\w\\d_-]+\\.+[\\w]\/i.test(str)) \trequired: (str) -&gt; \t\t(@min_length str, 1) \tmin_value: (num,value) -&gt; \t\t(num &gt; value) \tmax_value: (num,value) -&gt; \t\t(num &lt; value) \tnumeric: (num) -&gt;  \t\t(\/[^\\d]\/g.test(num)) \talpha_numeric: (str) -&gt; \t\t(\/[^\\da-z]\/gi.test(str)) \ttrim: (str) -&gt; \t\tstr.replace \/^\\s+|\\s+$\/g, '' \tinteger: (str) -&gt; \t\tparseInt(str) \tparse_rules: (rules) -&gt; \t\trules.split '|' \tvalidate_field: (field,str,rules) -&gt; \t\trules = @parse_rules rules \t\tfor rule_string in rules \t\t\t[rule,value] = @rule_value(rule_string) \t\t\tresult = @[rule] str, value \t\t\tunless result in [true,false] # post processing \t\t\t\tstr = @data[field] = result \t\t\telse unless 'required' not in rules and str.length is 0 \t\t\t\tif result is no \t\t\t\t\t@set_error field, rule_string \t\t\t\t\tbreak \tset_error: (field,rule) -&gt; \t\tif @errors_list is undefined \t\t\t@errors_list = {} \t\tif @errors_list[field] is undefined \t\t\t@errors_list[field] = [] \t\t@errors_list[field].push rule <\/code><\/pre>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0438 \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u2013 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 CoffeeScript \u044d\u0442\u043e \u043b\u0435\u0433\u043a\u043e \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  <i>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043b\u0438\u043a\u0431\u0435\u0437. \u041c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 \u2013 \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430. \u0412 JavaScript (\u0438 \u0432 CoffeeScript \u0442\u043e\u0436\u0435, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f) \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u2013 \u0442\u043e\u0447\u043a\u0443. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0438\u0436\u0435.<\/i><\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 find \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0432 \u0434\u0443\u0445\u0435 CodeIgniter. \u0412 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0433\u0434\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0435\u043a\u0435\u043d\u0434\u0430 \u0432\u044b\u0441\u0442\u0443\u043f\u0438\u043b CI, \u043c\u043d\u0435 \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0430\u0432\u0438\u043b \u0432 \u043a\u043b\u0438\u0435\u043d\u0442.<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 validate, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u0435\u0439 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434 \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0447\u0438\u0441\u0442\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0435\u0442 \u0431\u0440\u0430\u0442\u0430 show_errors() \u0438 \u0432\u0435\u0440\u043d\u0443\u0442 false. \u0414\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f, \u043a\u0430\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0438 \u043f\u043e \u044d\u0442\u043e\u0439 \u0436\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043e\u043d\u0438 \u043e\u0447\u0438\u0449\u0430\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c.<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 show_errors \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0440\u044f\u0434\u043e\u043c \u0441 \u043f\u043e\u043b\u044f\u043c\u0438 \u0444\u043e\u0440\u043c\u044b, \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 \u0444\u043e\u043a\u0443\u0441 (\u043a\u0443\u0440\u0441\u043e\u0440) \u0432 \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u043e\u043b\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u043e\u0448\u0438\u0431\u043a\u0443. <\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 lang \u043d\u0430\u0439\u0434\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435, \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u0432 \u043d\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0435\u0441\u0442\u044c, \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 rule_value \u0432\u0435\u0440\u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0430\u0432\u0438\u043b\u0430. \u0421\u0434\u0435\u043b\u0430\u043d\u043e \u043d\u0430 \u0441\u043a\u043e\u0440\u0443\u044e \u0440\u0443\u043a\u0443, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u2013 \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u041b\u0421 \u0438\u043b\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043a\u043e\u0434.<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434\u044b min_length, max_length, valid_email, required, min_value, max_value, numeric \u0438 alpha_numeric \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438. \u0412\u044b \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<p>  \u041a\u0430\u043a \u0438 \u0432 CodeIgniter, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u0438 \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u0438\u0445. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b trim \u0438 integer.<\/p>\n<p>  \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 parse_rules \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u0440\u0430\u0432\u0438\u043b, \u043e\u0442\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0432 \u0434\u0443\u0445\u0435 CodeIgniter, \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0435\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432.<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 validate_field, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044f, \u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0435\u0435 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 set_error \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u0441\u0438\u044f \u043a\u043e\u0434\u0430 \u0441 \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438.<\/p>\n<pre><code class=\"python\">class validation \tfind: (rules, rule) -&gt; \t\t# \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0432 \u043f\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0443 | \t\trules = rules.split '|' \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 - \u0435\u0441\u0442\u044c \u043b\u0438 rule \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 rules \t\t(rule in rules) \tvalidate: (rules) -&gt; \t\t# \u0443\u0434\u0430\u043b\u0438\u0442 \u0432\u0441\u0435 \u043e\u0442\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 - \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c .form_error \t\t$('.form_error').remove() \t\t# \u0443\u0434\u0430\u043b\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0448\u0438\u0431\u043e\u043a \t\tdelete @errors_list \t\t# \u043e\u0447\u0438\u0441\u0442\u0438\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \t\t@fields = {} \t\t# \u0441\u043e\u0437\u0434\u0430\u0435\u0442 (\u043e\u0447\u0438\u0449\u0430\u0435\u0442) \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \t\t@data = {} \t\t# \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \t\tfor field, rule of rules \t\t\t# \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u0435 \u0444\u043e\u0440\u043c\u044b (\u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f) \t\t\t@fields[field] = $(&quot;input[name=\\&quot;#{field}\\&quot;]&quot;); \t\t\t# \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \t\t\t@data[field] = @fields[field].val() \t\t\t# \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \t\t\t@validate_field field, @data[field], rules_string \t\t# \u0435\u0441\u043b\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \t\tunless @errors_list?  \t\t\t# \u0432\u0435\u0440\u043d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \t\t\t@data \t\telse \t\t\t# \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \t\t\t@show_errors() \t\t\t# \u0432\u0435\u0440\u043d\u0435\u0442 false \t\t\tfalse \tshow_errors: -&gt; \t\t# \u043e\u0442\u043c\u0435\u0442\u0438\u0442, \u0447\u0442\u043e \u0444\u043e\u043a\u0443\u0441 \u0435\u0449\u0435 \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0441\u044f \t\tfocus_set = false \t\t# \u043e\u0431\u043e\u0439\u0434\u0435\u0442 \u0432 \u0446\u0438\u043a\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \t\tfor field, errors of @errors_list \t\t\t# \u0442\u0443\u0442 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \t\t\tmessages = [] \t\t\tfor error in errors  \t\t\t\t# \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0432 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0432\u0438\u0434 \t\t\t\tmessages.push @lang error \t\t\t# \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u043f\u043e\u043b\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u0435\u043c \t\t\t@fields[field].before nano templates.form_error, {message: messages.join(' ')} \t\t\t# \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0444\u043e\u043a\u0443\u0441 \u0432 \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u043e\u043b\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \t\t\tunless focus_set \t\t\t\t@fields[field].focus() \t\t\t\tfocus_set = true \tlang: (error) -&gt; \t\t# \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0435\u0441\u0442\u044c \t\t[rule,value] = @rule_value error \t\tif value? \t\t\t# \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \t\t\tnano lang.errors[rule], {val: value}) \t\telse \t\t\t# \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0442 - \u0432\u0435\u0440\u043d\u0435\u0442 \u044f\u0437\u044b\u043a\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u0430\u043a \u0435\u0441\u0442\u044c \t\t\tlang.errors[rule] \trule_value: (rule)-&gt; \t\t# \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u0432\u0438\u0434\u0430 min_length[3] \t\tx = rule.split '[' \t\tif x[1]? \t\t\tif x[1].substr(x[1].length - 1) == ']' \t\t\t\tx[1] = x[1].substr 0, x[1].length - 1 \t\t[x[0],x[1]] \tmin_length: (str,length) -&gt; \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \t\t(str.length &gt;= length) \tmax_length: (str,length) -&gt; \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \t\t(str.length &lt; length) \tvalid_email: (str) -&gt; \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 \t\t(\/^[\\w\\d_-]+@+[\\w\\d_-]+\\.+[\\w]\/i.test(str)) \trequired: (str) -&gt; \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0435 \u043f\u0443\u0441\u0442\u0430\u044f \t\t(@min_length str, 1) \tmin_value: (num,value) -&gt; \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \t\t(num &gt; value) \tmax_value: (num,value) -&gt; \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \t\t(num &lt; value) \tnumeric: (num) -&gt;  \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440\u044b \t\t(\/[^\\d]\/g.test(num)) \talpha_numeric: (str) -&gt; \t\t# \u0432\u0435\u0440\u043d\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440\u044b \u0438 \u0431\u0443\u043a\u0432\u044b \t\t(\/[^\\da-z]\/gi.test(str)) \ttrim: (str) -&gt; \t\t# \u043e\u0447\u0438\u0441\u0442\u0438\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0438\u0445 \u0438 \u0437\u0430\u043c\u044b\u043a\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0431\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \t\tstr.replace \/^\\s+|\\s+$\/g, '' \tinteger: (str) -&gt; \t\t# \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u0432 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u0438\u0434 \t\tparseInt(str) \tparse_rules: (rules) -&gt; \t\t# \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u0440\u0430\u0432\u0438\u043b \u0432 \u043c\u0430\u0441\u0441\u0438\u0432  \t\trules.split '|' \tvalidate_field: (field,str,rules) -&gt; \t\t# \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u0440\u0430\u0432\u0438\u043b \u0432 \u043c\u0430\u0441\u0441\u0438\u0432  \t\trules = @parse_rules rules \t\t# \u0432 \u0446\u0438\u043a\u043b\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \t\tfor rule_string in rules \t\t\t# \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0435\u0441\u0442\u044c \t\t\t[rule,value] = @rule_value(rule_string) \t\t\t# \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043a\u043e\u043b\u0431\u0435\u043a \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \t\t\tresult = @[rule] str, value \t\t\t# \u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 - \u0447\u0442\u043e-\u0442\u043e, \u043a\u0440\u043e\u043c\u0435 false \u0438\u043b\u0438 true \t\t\t# - \u0437\u043d\u0430\u0447\u0438\u0442 \u0431\u044b\u043b\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \t\t\tunless result in [true,false] \t\t\t\t# \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \t\t\t\tstr = @data[field] = result \t\t\t# \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u043f\u0443\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \t\t\telse unless 'required' not in rules and str.length is 0 \t\t\t\tif result is no \t\t\t\t\t# \u043b\u043e\u0432\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \t\t\t\t\t@set_error field, rule_string \t\t\t\t\t# \u0430 \u0441\u043c\u044b\u0441\u043b \u0434\u0430\u043b\u044c\u0448\u0435 \u0438\u0441\u043a\u0430\u0442\u044c?  \t\t\t\t\t# \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 - \u0443\u0431\u0435\u0440\u0438\u0442\u0435 \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443, \t\t\t\t\t# \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u043d\u0430\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u044f \u0441 CI \t\t\t\t\tbreak \tset_error: (field,rule) -&gt; \t\t# \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0448\u0438\u0431\u043e\u043a, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442 \t\tif @errors_list is undefined \t\t\t@errors_list = {} \t\t# \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0432\u0435\u0442\u043a\u0443 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0435\u0449\u0435 \u043d\u0435\u0442 \t\tif @errors_list[field] is undefined \t\t\t@errors_list[field] = [] \t\t# \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \t\t@errors_list[field].push rule <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435.<\/p>\n<pre><code class=\"python\">lang =  \terrors: \t\tmin_length: '\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430, \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c {val} \u0441\u0438\u043c\u0432.' \t\tmax_length: '\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c {val} \u0441\u0438\u043c\u0432.' \t\tmin_value: '\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c {val}.' \t\tmax_value: '\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0435\u0436\u043d\u043e \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 {val}.' \t\tnumeric: '\u0414\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440\u044b.' \t\talpha_numeric: '\u0414\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440\u044b \u0438 \u0431\u0443\u043a\u0432\u044b \u043b\u0430\u0442\u0438\u043d\u0438\u0446\u044b.' \t\tvalid_email: '\u041d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b.' \t\trequired: '\u0417\u0434\u0435\u0441\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435.' <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0439 JS-\u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440, \u0432\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434, \u0443\u0436\u0435 \u043d\u0430 CoffeeScript<\/p>\n<pre><code class=\"python\">_nano_regex = \/\\{([\\w\\.]*)\\}\/g nano = (template, data) -&gt; \ttemplate.replace _nano_regex, (str, key) -&gt; \t\tkeys = key.split(&quot;.&quot;) \t\tvalue = data[keys.shift()] \t\t$.each keys, -&gt; \t\t\tvalue = value[this] \t\t(if (value is null or value is `undefined`) then &quot;&quot; else value) <\/code><\/pre>\n<p>  \u041e\u0444\u0444\u0442\u043e\u043f. \u0412\u043e\u0442 \u0432\u0430\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043e\u0434\u0430\u0440\u043e\u043a \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"python\">add_quotes = (str) -&gt; \t(if str? then str.replace \/&quot;\/g, &quot;&quot;&quot; else '') <\/code><\/pre>\n<h1>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h1>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u0432 \u0444\u043e\u0440\u043c\u0435<\/p>\n<pre><code class=\"html\">&lt;label&gt;\u0418\u043c\u044f&lt;\/label&gt; &lt;input type=\u201dtext\u201d name=\u201dname\u201d value=\u201d\u0412\u0430\u0441\u0438\u043b\u0438\u0439\u201d&gt; &lt;label&gt;\u0424\u0430\u043c\u0438\u043b\u0438\u044f&lt;\/label&gt; &lt;input type=\u201dtext\u201d name=\u201dsurname\u201d&gt; &lt;label&gt;\u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043f\u043e\u0447\u0442\u0430&lt;\/label&gt; &lt;input type=\u201dtext\u201d name=\u201demail\u201d&gt; <\/code><\/pre>\n<p>  \u0422\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e \u0441\u0430\u0431\u043c\u0438\u0442\u0443 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<pre><code class=\"python\">rules = \tname: 'trim|required|min_length[2]|max_length[255]' \tsurname: 'trim|max_length[255]' \temail: 'trim|required|valid_email|max_length[255]'  validation = new validation  $('body').on 'submit', 'form', =&gt; \tdata = validation.validate rules \tif data isnt off \t\t# \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0445 \u0430\u044f\u043a\u0441\u043e\u043c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \telse \t\t# \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0438\u043b\u0438\u0441\u044c. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043c\u043e\u0436\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u2013 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438 \u0434\u0430\u0436\u0435 \u043a\u0443\u0440\u0441\u043e\u0440 \u0432\u0441\u0442\u0430\u043d\u0435\u0442 \u0432 \u043d\u0443\u0436\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 <\/code><\/pre>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u0447\u0438 \u0432\u0430\u043c!    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/184344\/\"> http:\/\/habrahabr.ru\/post\/184344\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435. \u0417\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043c\u044b \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0432 \u041b\u0421.<\/p>\n<p>  \u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e  <\/p>\n<ul>\n<li>\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f CoffeeScript<\/li>\n<li>\u201c\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0435\u201d \u041e\u041e\u041f \u0441 CoffeeScript<\/li>\n<li>\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0443\u0434\u0430\u0447\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/li>\n<li>jQuery \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 CoffeeScript<\/li>\n<li>\u043c\u0438\u043a\u0440\u043e\u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u043d\u0430 CoffeeScript<\/li>\n<\/ul>\n<p>  <\/p>\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-184344","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/184344","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=184344"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/184344\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}