0

If I wanted this to also validate that there were 5 digits that were only numbers in the zip code field and at least 10 digits with no letters other than () or - in the phone number field how would I add that into this code? Thanks!

 if (jQuery('#first_name').val() !== '' && jQuery('#last_name').val() !== '' && jQuery('#zip_code').val() !== '' && jQuery('#phone_number').val() !== '')  {
        jQuery(".home_step_two .next_incomplete").hide();
        jQuery(".home_step_two .next").show();
    } else {
        jQuery(".home_step_two .next").hide();
        jQuery(".home_step_two .next_incomplete").show();
    }
avan
  • 1

1 Answers1

0
zipCodeRight=()=>parseInt(jQuery('#zip_code').val(),10) && jQuery("#zip_code").val().length== 5;
phoneNumberRight=()=>jQuery("#phone_number").val().length>10&& jQuery("#phone_number").val().split("").every(el=>"0123456789-+()".split("").indexOf(el)+1);

if(zipCodeRight() && phoneNumberRight()){
  alert("allright");
}

Simply check if the zipCode can be converted to a number and if its length is 5 and if the phonenumber only contains "0123456789()+-" ...

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
  • Thank you Jonas! I'm getting an error at the first => If I understand correctly that has to do with an array (sorry still new to programming) but the first part of it zipCodeRight=() what is that doing, I haven't seen the =() before. Any idea why id be getting an error at the => ? – avan May 08 '17 at 18:52
  • @avan update your browser... thats called *arrow function* – Jonas Wilms May 09 '17 at 12:50
  • Thanks for the reply, unfortunately that wont work for me as I have to have support for this code all the way back to IE7 for our user base. – avan May 09 '17 at 14:31
  • @avan so you arent able to change *()=>...* to *function(){ return ...}* ? – Jonas Wilms May 09 '17 at 14:33