php - check for valid 5 and 6 digit zipcode -


i able autofill state,city , area based on 6 digit zipcode.the issue comes when want check validity of zipcode starting 5th digit.i know show invalid zip code error comparing value against database value..here goes code have used. there way can hide error of invalid zip code after 5th digit while still continuing validate after 5th digit of zipcode?

<script>     require([         'jquery'     ],function($){         $(document).ready(function(){             $('#seller_zipcode').keyup(function() {                 pincode = $('#seller_zipcode').val();                 pincode1 = $('#seller_zipcode').slice(0,-1);                 //pincode1 = pincode.slice(0,-1);                 //console.log(pincode1);                 if(pincode.length == 6 || pincode1.length == 5){                     $.ajax({                         type: 'post'                         ,url: "<?php echo $block->geturl('marketplace/zipcode/zipcode');?>"                         ,data: {pincode : pincode}                         ,success: function(result){                             var finalresult = $.parsejson(result);                             console.log(finalresult);                             if(finalresult.state != null){                                 $('#state').val(finalresult.state);                                 $('#seller_district').val(finalresult.district);                                 $('#seller_taluka').val(finalresult.area);                                 $('#zip_error').removeclass('mage-error');                                 $('#zip_error').removeattr('generated');                                 $('#zip_error').html("");                             }                             else{                                 $('#state').val("");                                 $('#seller_district').val("");                                 $('#seller_taluka').val("");                                 $('#zip_error').removeclass('mage-error');                                 $('#zip_error').addclass('mage-error').html("zip code invalid").show();                                 $('#zip_error').attr('generated','true');                             }                         }                     });                 }             }); 

try doing this:

<script>     require([         'jquery'     ],function($){         $(document).ready(function(){             $('#seller_zipcode').keyup(function() {                  //reset zip error                 $('#zip_error').removeclass('mage-error');                 $('#zip_error').removeattr('generated');                 $('#zip_error').html("");                   pincode = $('#seller_zipcode').val();                 pincode1 = $('#seller_zipcode').slice(0,-1);                 //pincode1 = pincode.slice(0,-1);                 //console.log(pincode1);                 if(pincode.length == 6 || pincode1.length == 5){                     $.ajax({                         type: 'post'                         ,url: "<?php echo $block->geturl('marketplace/zipcode/zipcode');?>"                         ,data: {pincode : pincode}                         ,success: function(result){                             var finalresult = $.parsejson(result);                             console.log(finalresult);                             if(finalresult.state != null){                                 $('#state').val(finalresult.state);                                 $('#seller_district').val(finalresult.district);                                 $('#seller_taluka').val(finalresult.area);                                 $('#zip_error').removeclass('mage-error');                                 $('#zip_error').removeattr('generated');                                 $('#zip_error').html("");                             }                             else{                                 $('#state').val("");                                 $('#seller_district').val("");                                 $('#seller_taluka').val("");                                 $('#zip_error').removeclass('mage-error');                                 $('#zip_error').addclass('mage-error').html("zip code invalid").show();                                 $('#zip_error').attr('generated','true');                             }                         }                     });                 }             }); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -