Skip to main content
deleted 12 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Changes I would make  : (but not necessary)
 

  • make sure inputtext has a value, and isn't undefined, so it wouldn't throw an error in your if statement.

    Make sure inputtext has a value, and isn't undefined, so it wouldn't throw an error in your if statement.
  • Replace the if statement with return instead. (This is mostly to minimize the code a bit, something your minifier won't do for you).
    Except for that it seems ok (not looking into the logic of the regex, since im not sure how a zipcode should be parsed)

    function zipcode (inputtxt)
    {

     if (!inputtxt || !inputtxt.value) return false;
     var zipcode = /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;  
    
     return ((inputtxt.value.match(zipcode));
    

    }

    Replace the if statement with return instead. (This is mostly to minimize the code a bit, something your minifier won't do for you).

Except for that, it seems ok (I'm not looking into the logic of the regex, since I'm not sure how a zipcode should be parsed).

function zipcode (inputtxt)    
{  

    if (!inputtxt || !inputtxt.value) return false;
    var zipcode = /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;  

    return ((inputtxt.value.match(zipcode));
} 

Changes I would make  : (but not necessary)
 

  • make sure inputtext has a value, and isn't undefined, so it wouldn't throw an error in your if statement.

  • Replace the if statement with return instead. (This is mostly to minimize the code a bit, something your minifier won't do for you).
    Except for that it seems ok (not looking into the logic of the regex, since im not sure how a zipcode should be parsed)

    function zipcode (inputtxt)
    {

     if (!inputtxt || !inputtxt.value) return false;
     var zipcode = /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;  
    
     return ((inputtxt.value.match(zipcode));
    

    }

Changes I would make: (but not necessary)

  • Make sure inputtext has a value, and isn't undefined, so it wouldn't throw an error in your if statement.
  • Replace the if statement with return instead. (This is mostly to minimize the code a bit, something your minifier won't do for you).

Except for that, it seems ok (I'm not looking into the logic of the regex, since I'm not sure how a zipcode should be parsed).

function zipcode (inputtxt)    
{  

    if (!inputtxt || !inputtxt.value) return false;
    var zipcode = /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;  

    return ((inputtxt.value.match(zipcode));
} 
Source Link
gillyb
  • 131
  • 2

Changes I would make : (but not necessary)

  • make sure inputtext has a value, and isn't undefined, so it wouldn't throw an error in your if statement.

  • Replace the if statement with return instead. (This is mostly to minimize the code a bit, something your minifier won't do for you).
    Except for that it seems ok (not looking into the logic of the regex, since im not sure how a zipcode should be parsed)

    function zipcode (inputtxt)
    {

     if (!inputtxt || !inputtxt.value) return false;
     var zipcode = /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;  
    
     return ((inputtxt.value.match(zipcode));
    

    }