-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisValid.js
More file actions
21 lines (18 loc) · 706 Bytes
/
Copy pathisValid.js
File metadata and controls
21 lines (18 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Zip codes consist of 5 consecutive digits. Given a string, write a function to determine whether the input is a valid zip code.
// A valid zip code is as follows:
// Must only contain numbers (no non-digits allowed).
// Must not contain any spaces.
// Must not be greater than 5 digits in length.
// Examples:
// isValid("59001") ➞ true
// isValid("853a7") ➞ false
// isValid("732 32") ➞ false
// isValid("393939") ➞ false
function isValid(zip) {
// let num = Number(zip);
// // console.log(zip.length);
// return /\s/.test(zip) || zip.length > 5 || !num ? false : true;
console.log(!isNaN(zip));
// return zip.length == 5 && !isNaN(zip);
}
console.log(isValid("59220"));