JavaScript:ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits. If the function is passed a valid PIN string, return true, else return false
时间: 2024-04-03 21:34:06 浏览: 124
电子时钟字体文件electronicFont DS-DIGIT.TTF
Certainly! Here's a JavaScript function that checks if a PIN string is valid according to the given conditions:
```javascript
function validatePIN(pin) {
if (pin.length === 4 || pin.length === 6) {
if (/^\d+$/.test(pin)) {
return true;
}
}
return false;
}
```
You can use this function by passing a PIN string to it. It will return `true` if the PIN is valid (contains exactly 4 or 6 digits only), and `false` otherwise.
阅读全文