programming-examples/js/Vre1/Check whether a given value is US zip code or not.js
2019-11-15 12:59:38 +01:00

17 lines
340 B
JavaScript

function is_usZipCode(str)
{
regexp = /^[0-9]{5}(?:-[0-9]{4})?$/;
if (regexp.test(str))
{
return true;
}
else
{
return false;
}
}
console.log(is_usZipCode("03201-2150"));
console.log(is_usZipCode("7892"));