mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-29 18:28:06 +03:00
30 lines
678 B
TypeScript
30 lines
678 B
TypeScript
export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;
|
|
|
|
export function generateCardNumber(): string {
|
|
let cardId = '';
|
|
|
|
while (true) {
|
|
// don't start with a 3
|
|
const firstDigit = Math.floor(Math.random() * 10);
|
|
|
|
if (firstDigit !== 3) {
|
|
cardId = firstDigit.toString();
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (let i = 0; i < 19; i++) {
|
|
cardId += Math.floor(Math.random() * 10).toString();
|
|
}
|
|
|
|
return cardId;
|
|
}
|
|
|
|
/**
|
|
* Validates the provided card id by known parameters
|
|
* @param id The card id to validate
|
|
*/
|
|
export function validateCardId(id: string): boolean {
|
|
return id[0] !== '3' && CARD_ID_REGEX.test(id);
|
|
}
|