1 2$(document).on('blur', 'input.validate_text', function() 3{ 4 var id = $(this); 5 var length = 2; 6 validateText(id, true, length); 7}); 8 9$(function() 10{ 11 validated = []; 12 13 $('input.validate_ok').each (function() 14 { 15 var id = $(this); 16 id.blur(function() { validateOK(id, true); }); 17 }); 18 19 $('textarea.validate_text').each (function() 20 { 21 var id = $(this); 22 var length = 2; 23 id.blur(function() { validateText(id, true, length); }); 24 }); 25 26 $('input.validate_text_short').each (function() 27 { 28 var id = $(this); 29 var length = 1; 30 id.blur(function() { validateText(id, true, length); }); 31 }); 32 33 $('input.validate_text_long').each (function() 34 { 35 var id = $(this); 36 var length = 9; 37 id.blur(function() { validateText(id, true, length); }); 38 }); 39 40 $('input.validate_psc').each (function() 41 { 42 var id = $(this); 43 id.blur(function() { validatePSC(id, true); }); 44 }); 45 46 $('input.validate_text_vlong').each (function() 47 { 48 var id = $(this); 49 var length = 9; 50 id.blur(function() { validateText(id, true, length); }); 51 }); 52 53 $('input.validate_text_space:visible').each (function() 54 { 55 var id = $(this); 56 id.data('validation_type', 'text_space'); 57 id.blur(function() { validateText(id, true, length); }); 58 }); 59 60 $('input.validate_birthyear:visible').each (function() 61 { 62 var id = $(this); 63 id.blur(function() { validateBirthYear(id, true); }); 64 }); 65 66 $('input.validate_email').each (function() 67 { 68 var id = $(this); 69 id.blur(function() { validateEmail(id, true); }); 70 }); 71 72 $('select.validate_select:visible').each (function() 73 { 74 var id = $(this); 75 id.change(function() { validateSelect(id, true); }); 76 }); 77 78 $('input.validate_checkbox:visible').each (function() 79 { 80 var id = $(this); 81 id.change(function() { validateCheckbox(id, true); }); 82 }); 83 84 $('input.validate_equally:visible').each (function() 85 { 86 var id = $(this); 87 88 id.blur(function() { validateEqually(id, true); }); 89 }); 90 91}); 92 93$(document).on('submit', "#form", function(e) 94{ 95 if(validation()) 96 { 97 return true; 98 } 99 else 100 { 101 return false; 102 } 103}); 104 105$(document).on('submit', ".form_validation", function(e) 106{ 107 if(validation()) 108 { 109 return true; 110 } 111 else 112 { 113 return false; 114 } 115}); 116 117function formValidation(form) 118{ 119 var formok = true; 120 var error = null; 121 122 form.find('input.validate_text:visible').each (function() 123 { 124 var id = $(this); 125 var length = 2; 126 if(!validateText(id, true, length)) 127 { 128 if (!error && id.data("validation_only_ok") != 1) error = id; 129 formok = false; 130 } 131 }); 132 133 form.find('textarea.validate_text:visible').each (function() 134 { 135 var id = $(this); 136 var length = 2; 137 if(!validateText(id, true, length)) 138 { 139 if (!error && id.data("validation_only_ok") != 1) error = id; 140 formok = false; 141 } 142 }); 143 144 if (error) 145 { 146 error.focus(); 147 } 148 149 return formok; 150} 151 152function validation() 153{ 154 var formok = true; 155 var error = null; 156 $('input.validate_text:visible').each (function() 157 { 158 var id = $(this); 159 var length = 2; 160 if(!validateText(id, true, length)) 161 { 162 if (!error && id.data("validation_only_ok") != 1) error = id; 163 formok = false; 164 } 165 }); 166 167 $('input.validate_ok:visible').each (function() 168 { 169 var id = $(this); 170 validateOK(id, true); 171 }); 172 173 $('input.validate_text_unv').each (function() 174 { 175 var id = $(this); 176 var length = 2; 177 if(!validateText(id, true, length)) 178 { 179 if (!error) error = id; 180 formok = false; 181 } 182 }); 183 184 $('textarea.validate_text:visible').each (function() 185 { 186 var id = $(this); 187 var length = 2; 188 if(!validateText(id, true, length)) 189 { 190 if (!error && id.data("validation_only_ok") != 1) error = id; 191 formok = false; 192 } 193 }); 194 195 $('input.validate_text_short:visible').each (function() 196 { 197 var id = $(this); 198 var length = 1; 199 if(!validateText(id, true, length)) 200 { 201 if (!error) error = id; 202 formok = false; 203 } 204 }); 205 206 $('input.validate_text_long:visible').each (function() 207 { 208 var id = $(this); 209 var length = 5; 210 if(!validateText(id, true, length)) 211 { 212 if (!error) error = id; 213 formok = false; 214 } 215 }); 216 217 $('input.validate_text_vlong:visible').each (function() 218 { 219 var id = $(this); 220 var length = 9; 221 if(!validateText(id, true, length)) 222 { 223 if (!error) error = id; 224 formok = false; 225 } 226 }); 227 228 $('input.validate_psc:visible').each (function() 229 { 230 var id = $(this); 231 if(!validatePSC(id, true)) 232 { 233 if (!error) error = id; 234 formok = false; 235 } 236 }); 237 238 $('input.validate_text_space:visible').each (function() 239 { 240 var id = $(this); 241 id.data('validation_type', 'text_space'); 242 var length = 2; 243 if(!validateText(id, true, length)) 244 { 245 if (!error) error = id; 246 formok = false; 247 } 248 }); 249 250 $('input.validate_birthyear:visible').each (function() 251 { 252 var id = $(this); 253 if(!validateBirthYear(id, true)) 254 { 255 if (!error) error = id; 256 formok = false; 257 } 258 }); 259 260 $('input.validate_email:visible').each (function() 261 { 262 var id = $(this); 263 if(!validateEmail(id, true)) 264 { 265 if (!error) error = id; 266 formok = false; 267 } 268 }); 269 270 $('input.validate_checkbox').each (function() 271 { 272 var id = $(this); 273 if(!validateCheckbox(id, true)) 274 { 275 formok = false; 276 } 277 }); 278 279 $('select.validate_select').each (function() 280 { 281 var id = $(this); 282 if(!validateSelect(id, true)) 283 { 284 formok = false; 285 } 286 }); 287 288 if (formok) 289 { 290 $('input.validate_equally').each (function() 291 { 292 var id = $(this); 293 if(!validateEqually(id, true)) 294 { 295 formok = false; 296 } 297 });
298 } 299 300 $('.validate_own:visible').each (function() 301 { 302 var id = $(this); 303 if(id.data("validated") != 1) 304 { 305 if (!error) error = id; 306 formok = false; 307 } 308 }); 309 310 311 if (error) 312 { 313 error.focus(); 314 } 315 316 return formok; 317} 318 319function validateEqually(id, first) 320{ 321 var first = first; 322 var second_id = id.data('validation-equally'); 323 var second = $('#' + second_id); 324 325 var val = id.val(); 326 var second_val = second.val(); 327 328 var label = $('label[for="' + id.attr('id') + '"]'); 329 330 var result = false; 331 if (!val || !second_val) result = true; 332 333 if ($.inArray("equally-" + id, validated)) 334 { 335 id.keyup(function() { validateEqually(id, first); }); 336 validated.push("equally-" + id); 337 } 338 339 if (val == second_val) result = true; 340 341 var palert = $('p.alert_' + id.attr('id')); 342 var equally_alert = $('p.alert_equally_' + id.attr('id')); 343 344 if (palert.is(":visible")) return true; 345 346 var second_palert = $('p.alert_' + second.attr('id')); 347 var second_label = $('label[for="' + second.attr('id') + '"]'); 348 var second_alert = $('p.alert_equally_' + second.attr('id')); 349 350 if (result == true) 351 { 352 id.removeClass("error_input"); 353 label.removeClass("error"); 354 equally_alert.hide(); 355 356 if (second_alert.is(":visible")) 357 { 358 second.removeClass("error_input"); 359 second_label.removeClass("error"); 360 second_alert.hide(); 361 } 362 363 return true; 364 } 365 else 366 { 367 id.addClass("error_input"); 368 label.addClass("error"); 369 equally_alert.show(); 370 371 if (!second_alert.is(":visible") && !second_palert.is(":visible")) 372 { 373 second.addClass("error_input"); 374 second_label.addClass("error"); 375 second_alert.show(); 376 } 377 378 return false; 379 } 380} 381 382function validateCheckbox(id, first) 383{ 384 var id = id; 385 var first = first; 386 var length = length; 387 var label = $('label[for="' + id.attr('id') + '"]'); 388 var rel = id.attr('rel'); 389 var palert = $('p.alert_' + id.attr('id')); 390 if (first) 391 { 392 id.keyup(function() { validateCheckbox(id, first) }); 393 first = false; 394 } 395 396 if(id.is(":checked")) 397 { 398 id.removeClass("error_input"); 399 label.removeClass("error"); 400 palert.hide(); 401 return true; 402 } 403 else 404 { 405 id.addClass("error_input"); 406 label.addClass("error"); 407 palert.show(); 408 return false; 409 } 410} 411 412function validateSelect(id, first) 413{ 414 var id = id; 415 var first = first; 416 var length = length; 417 var label = $('label[for="' + id.attr('id') + '"]'); 418 var rel = id.attr('rel'); 419 var palert = $('p.alert_' + id.attr('id')); 420 if (first) 421 { 422 id.keyup(function() { validateSelect(id, first) }); 423 first = false; 424 } 425 426 if(id.val() != 0) 427 { 428 id.removeClass("error_input"); 429 label.removeClass("error"); 430 palert.hide(); 431 return true; 432 } 433 else 434 { 435 id.addClass("error_input"); 436 label.addClass("error"); 437 palert.show(); 438 return false; 439 } 440} 441 442function validateOK(nod, first) 443{ 444 var id = nod.attr("id"); 445 var palert_ok = $('p.alert_ok_' + id); 446 447 if (first) 448 { 449 nod.keyup(function() { validateOK(nod, first) }); 450 first = false; 451 } 452 453 if (nod.val()) 454 { 455 palert_ok.show(); 456 } 457 else 458 { 459 palert_ok.hide(); 460 } 461} 462 463function validateText(nod, first, length) 464{ 465 var nod = nod; 466 var id = nod.attr('id'); 467 468 if (nod.data('skip_validation') == 1) 469 { 470 nod.data('skip_validation', 0); 471 return true; 472 } 473 474 if (!nod.hasClass('validate_text_unv') && !nod.is(":visible")) return true; 475 476 if (nod.hasClass('novalidate')) return true; 477 478 var go_empty = false; 479 var go_ok = false; 480 if (nod.data('validation_empty')) go_empty = true; 481 if (nod.data('validation_ok')) go_ok = true; 482 483 var first = first; 484 var length = length; 485 if (nod.data('length')) length = nod.data('length'); 486 487 if (nod.data('min_length')) length = nod.data('min_length'); 488 489 var max_length = null; 490 if (nod.data('max_length')) max_length = nod.data('max_length'); 491 492 if (!length) length = 2; 493 494 if (nod.data('validation_length')) length = nod.data('validation_length'); 495 496 var label = $('label[for="' + id + '"]'); 497 var palert = $('p.alert_' + id); 498 var rel = nod.attr('rel'); 499 500 if (go_empty) var palert_empty = $('p.alert_empty_' + id); 501 if (go_ok) var palert_ok = $('p.alert_ok_' + id); 502 503 if (first) 504 { 505 nod.keyup(function() { validateText(nod, first, length) }); 506 first = false; 507 } 508
509 var validation_type = 'text'; 510 if (nod.data('validation_type')) validation_type = nod.data('validation_type'); 511 512 if (validation_type == 'validate_text') validation_type = 'text'; 513 if (validation_type == 'validate_email') validation_type = 'email'; 514 515 var palert_count = palert.find('.count'); 516 517 if (palert_count.length) 518 { 519 palert_count.html(nod.val().length); 520 } 521 522 523 if (validation_type == 'text') 524 { 525 var result = true; 526 if (nod.val().length < length) var result = false; 527 528 if (max_length) 529 { 530 if (nod.val().length > max_length) var result = false; 531 } 532 } 533 534 if (validation_type == 'text_long') 535 { 536 length = 9; 537 if (nod.val().length < length) var result = false; 538 else var result = true; 539 } 540 541 if (validation_type == 'text_short') 542 { 543 length = 1; 544 if (nod.val().length < length) var result = false; 545 else var result = true; 546 } 547 548 if (validation_type == 'text_space') 549 { 550 length = 4; 551 552 if (nod.val().length < length || (nod.val().indexOf(" ") < 1)) var result = false; 553 else var result = true; 554 555 var string = $.trim(nod.val()); 556 var arr = string.split(" "); 557 var count = 0; 558 arr.forEach(function(e) 559 { 560 if (e.length >= 1) count++; 561 }); 562 563 if (count >= 2) var result = true; 564 else var result = false; 565 } 566 567 if (validation_type == 'email') 568 { 569 var nod_val = $.trim(nod.val()); 570 var nod_arr = nod_val.split('@'); 571 var email_domain = nod_arr[1]; 572 573 if (email_domain == 'senam.cz') nod.val(nod_arr[0] + '@seznam.cz'); 574 if (email_domain == 'sezam.cz') nod.val(nod_arr[0] + '@seznam.cz'); 575 if (email_domain == 'seznam.com') nod.val(nod_arr[0] + '@seznam.cz'); 576 if (email_domain == 'gmail.cz') nod.val(nod_arr[0] + '@gmail.com'); 577 if (email_domain == 'gail.com') nod.val(nod_arr[0] + '@gmail.com'); 578 if (email_domain == 'gmai.com') nod.val(nod_arr[0] + '@gmail.com'); 579 if (email_domain == 'volny.com') nod.val(nod_arr[0] + '@volny.cz'); 580 if (email_domain == 'voly.cz') nod.val(nod_arr[0] + '@volny.cz'); 581 if (email_domain == 'vony.cz') nod.val(nod_arr[0] + '@volny.cz'); 582 583 nod_val = nod.val(); 584 585 var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; 586 if (filter.test(nod_val)) var result = true; 587 else var result = false; 588 } 589 590 if (validation_type == 'birthyear') 591 { 592 var value = nod.val(); 593 value.trim(); 594 var ftwo = value.substring(0, 2); 595 var len = value.length; 596 if (ftwo == 19 || ftwo == 20) var result = true; 597 if (len != 4) var result = false; 598 } 599 600 if (validation_type == 'psc') 601 { 602 result = validatePSC(nod); 603 } 604 605 var go_error = true; 606 if (nod.data("validation_only_ok") == 1) go_error = false; 607 608 if (!result || nod.val() == rel) 609 { 610 if (go_error) 611 { 612 nod.addClass("error_input"); 613 label.addClass("error"); 614 } 615 616 var show_alert = true; 617 if (nod.val().length == 0 && go_empty) 618 { 619 palert_empty.show(); 620 show_alert = false; 621 } 622 if (nod.val().length > 0 && go_empty) palert_empty.hide(); 623 624 if (show_alert) palert.show(); 625 else palert.hide(); 626 627 if (go_ok) 628 { 629 palert_ok.hide(); 630 nod.removeClass("ok_input"); 631 label.removeClass("ok"); 632 } 633 return false; 634 } 635 else 636 { 637 if (go_error) 638 { 639 nod.removeClass("error_input"); 640 label.removeClass("error"); 641 } 642 643 palert.hide(); 644 if (go_empty) palert_empty.hide(); 645 if (go_ok) 646 { 647 palert_ok.show(); 648 nod.addClass("ok_input"); 649 label.addClass("ok"); 650 } 651 return true; 652 } 653} 654 655function validateBirthYear(id, first) 656{ 657 var id = id; 658 if (!id.is(":visible")) return; 659 660 var first = first; 661 var length = length; 662 var label = $('label[for="' + id.attr('id') + '"]'); 663 var palert = $('p.alert_' + id.attr('id')); 664 var rel = id.attr('rel'); 665 if (first) 666 { 667 id.keyup(function() { validateBirthYear(id, first) }); 668 first = false; 669 } 670 671 var error = true; 672 var value = id.val(); 673 value.trim(); 674 var ftwo = value.substring(0, 2); 675 var len = value.length; 676 value = parseInt(value); 677 678 if (ftwo == 19 || ftwo == 20) error = false; 679 if (len != 4) error = true; 680 681 if(error) 682 { 683 id.addClass("error_input"); 684 label.addClass("error"); 685 palert.show(); 686 return false; 687 } 688 else 689 { 690 id.removeClass("error_input"); 691 label.removeClass("error"); 692 palert.hide(); 693 return true; 694 } 695} 696 697function validateTextSpace(id, first, length) 698{ 699 var id = id; 700 var first = first; 701 var length = length; 702 var label = $('label[for="' + id.attr('id') + '"]'); 703 var alert = $('p.alert_' + id.attr('id')); 704 if (first) 705 { 706 id.keyup(function() { validateTextSpace(id, first, length) }); 707 first = false; 708 } 709 710 if(id.val().length < length || (id.val().indexOf(" ") < 1)) 711 { 712 id.addClass("error_input"); 713 label.addClass("error"); 714 alert.show(); 715 return false; 716 } 717 else
718 { 719 id.removeClass("error_input"); 720 label.removeClass("error"); 721 alert.hide(); 722 return true; 723 } 724} 725 726function validatePSC(id) 727{ 728 var id = id; 729 730 var val = id.val(); 731 val = val.replace(/\s+/g, ''); 732 id.val(val); 733 734 var country = id.data("country"); 735 736 var validated = false; 737 var region = null; 738 739 if (country == 'cz') 740 { 741 var first = val.substr(0, 1); 742 var two = val.substr(0, 2); 743 744 if (first == 1) region = 1; 745 else if (first == 2) region = 2; 746 else if (two == 46 || two == 47 || two == 51) region = 3; 747 else if (two == 43 || two == 41 || two == 40 || two == 44) region = 4; 748 else if (two == 35 || two == 36) region = 5; 749 else if (two >= 30 && two <= 34) region = 6; 750 else if (two >= 37 && two <= 39) region = 7; 751 else if (two == 58 || two == 59 || two == 67) region = 8; 752 else if (two == 53 || two == 56 || two == 57) region = 9; 753 else if (two == 50 || two == 54 || two == 55 || two == 51) region = 10; 754 else if (two == 68 || two == 61 || two == 62 || two == 63 || two == 64 || two == 66 || two == 69 || two == 60) region = 11; 755 else if (two == 79 || two == 78 || two == 77 || two == 75) region = 12; 756 else if (two == 76) region = 13; 757 else if (two >= 70 && two <= 74) region = 14; 758 } 759 760 if (country == 'sk') 761 { 762 var three = val.substr(0, 3); 763 764 var arr = []; 765 arr[17] = ['049','050','960','962','963','965','966','967','968','969','974','976','977','979','980','981','982','984','985','986','987','990','991','992']; 766 arr[18] = ['811', '821','831','841','851','900','901','902','903','906','908','925']; 767 arr[19] = ['040','044','045','048','049','052','053','055','056','071','072','073','075','076','077','078','079','980']; 768 arr[20] = ['925','927','930','934','935','936','937','940','941','942','943','945','946','947','949','951','952','953','955','956','966']; 769 arr[21] = ['053','054','058','059','060','061','062','064','065','066','067','068','069','080','082','083','085','086','087','089','090','091','093','094']; 770 arr[22] = ['017','018','019','020','906','907','911','913','914','915','916','956','957','958','971','972']; 771 arr[23] = ['905','906','908','909','917','919','920','921','922','924','925','926','929','930','931','932']; 772 arr[24] = ['010','013','014','015','022','023','024','026','027','028','029','031','032','033','034','036','038','039']; 773 774 775 arr.forEach(function(item, index) 776 { 777 item.forEach(function(pre, i) 778 { 779 if (pre == three) 780 { 781 region = index; 782 return; 783 } 784 }); 785 if (region) return; 786 }); 787 788 if (!region) 789 { 790 var first = val.substr(0, 1); 791 792 if (first == 8) region = 18; 793 } 794 795 796 /* 797 foreach (arr as key => ar) 798 { 799 if (in_array(three, ar)) 800 { 801 region = key; 802 break; 803 } 804 } 805 */ 806 } 807 808 if (region) 809 { 810 if (val.length == 5) validated = true; 811 812 if (id.data("region")) 813 { 814 if (id.data("region") != region) validated = false; 815 } 816 } 817 818 if (country == 'cz' && val == '06401') 819 { 820 validated = true; 821 } 822 823 return validated; 824} 825 826function validateTextArea(id, first, length) { 827 var id = id; 828 var first = first; 829 var length = length; 830 var label = $('label[for="' + id.attr('id') + '"]'); 831 var palert = $('p.alert_' + id.attr('id')); 832 var rel = id.attr('rel'); 833 if (first) 834 { 835 id.keyup(function() { validateText(id, first, length) }); 836 first = false; 837 } 838 if(id.val().length < length || id.val() == rel) 839 { 840 alert 841 id.addClass("error_input"); 842 label.addClass("error"); 843 return false; 844 } 845 846 else 847 { 848 id.removeClass("error_input"); 849 label.removeClass("error"); 850 return true; 851 } 852} 853 854function validateEmail(id, first) 855{ 856 var id = id; 857 if (!id.is(":visible")) return; 858 859 var first = first; 860 var label = $('label[for="' + id.attr('id') + '"]'); 861 var alert = $('p.alert_' + id.attr('id')); 862 if (first) 863 { 864 id.keyup(function() { validateEmail(id, first) }); 865 first = false; 866 } 867 868 var a = id.val(); 869
870 var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; 871 //var filter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 872 873 if(filter.test($.trim(a))) 874 { 875 id.removeClass("error_input"); 876 label.removeClass("error"); 877 alert.hide(); 878 return true; 879 } 880 881 else 882 { 883 id.addClass("error_input"); 884 label.addClass("error"); 885 alert.show(); 886 return false; 887 } 888} 889 890function isEmail(val) 891{ 892 var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; 893 if(filter.test($.trim(val))) return true; 894 else return false; 895}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.