Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Javascript Create function to validate usa zip codes

function validateZipCode(zipCode) {
    var regex = /^\d{5}$/;
    return regex.test(zipCode);

console.log(validateZipCode("12345")); // true
console.log(validateZipCode("12345-6789")); // true
console.log(validateZipCode("12345-6789-1234")); // false
console.log(validateZipCode("12345-6789-1234-1234")); // false
Enter fullscreen mode Exit fullscreen mode

Top comments (0)