Advertisement
ricomester

PhoneValideate_v2

Jun 23rd, 2022
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.     $(document).ready(function() {
  3.         $("form.form p.submit input").prop( "disabled", true );
  4.         $('.phone input.text').on("click", function() {
  5.             if( !$(this).val() ) {
  6.                 $(this).val("+36");
  7.             }
  8.         });
  9.    
  10.         $('.phone input.text').keyup(function(e) {
  11.            
  12.             var a = $(this).val();
  13.             var filter = /^([+]\d{10})/;
  14.             var errorbox = $("#error_for_" + $(".phone input.text").attr("id"));
  15.            
  16.             if(a.length < 11){
  17.                 $("form.form p.submit input").prop( "disabled", true );
  18.                
  19.             }
  20.             if(a.match(filter)) {
  21.                 if(a.length >= 11 && a.length < 14){
  22.                     errorbox.hide();
  23.                     $('.phone input.text').css("color", "#666");
  24.                     $("form.form p.submit input").prop( "disabled", false );
  25.                 } else {
  26.                     errorbox.show();
  27.                     errorbox.addClass("telefonhiba");
  28.                     errorbox.html('Kérjük, hogy a telefonszámot ilyen formátumban adja meg: +36123456789');
  29.                     errorbox.css({
  30.                         'color' : '#f36',
  31.                         'width' : '100%',
  32.                         'float' : 'right',
  33.                         'position' : 'relative',
  34.                         'top' : '-35px',
  35.                         'line-height' : '1.4',
  36.                         'margin-left' : '35px',
  37.                         'max-width' : '48%',
  38.                         'left' : '0'
  39.                     });
  40.                     $('.phone input.text').css("color", "red");
  41.                     $("form.form p.submit input").prop( "disabled", true );
  42.                    
  43.                 }
  44.             } else {
  45.                 errorbox.show();
  46.                 errorbox.addClass("telefonhiba");
  47.                 errorbox.html('Kérjük, hogy a telefonszámot ilyen formátumban adja meg: +36123456789');
  48.                 errorbox.css({
  49.                     'color' : '#f36',
  50.                     'width' : '100%',
  51.                     'float' : 'right',
  52.                     'position' : 'relative',
  53.                     'top' : '-35px',
  54.                     'line-height' : '1.4',
  55.                     'margin-left' : '35px',
  56.                     'max-width' : '48%',
  57.                     'left' : '0'
  58.                 });
  59.                 $('.phone input.text').css("color", "red");
  60.                 $("form.form p.submit input").prop( "disabled", true );
  61.                
  62.             }
  63.         });
  64.     });    
  65. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement