Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Validate US Zip Code in JavaScript</title>
</head>
  
<body>
<form>
<input id="txtZip" name="zip" type="text" /><br />
<input id="Button1" type="submit" value="Validate" 
onclick="IsValidZipCode(this.form.zip.value)" />
<p>This sample is from <a href="http://www.devcurry.com" target="_blank">DevCurry.com</a></p>
</form>
</body>
</html>
 
function IsValidZipCode(zip) {
  var isValid = /^[0-9]{3}(?:-[0-9]{4})?$/.test(zip);
            if (isValid)
                alert('Valid ZipCode');
            else {
                alert('Invalid ZipCode');
            }
        }
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers