2026-02-14 09:53:14 +01:00
|
|
|
import assert from 'node:assert';
|
2025-03-07 12:07:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// this currently does not match: "john.doe"@example.com, user@[192.168.1.1], john.doe(comment)@example.com or 用户@例子.世界
|
|
|
|
|
function isEmail(email) {
|
|
|
|
|
assert.strictEqual(typeof email, 'string');
|
|
|
|
|
|
|
|
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
|
|
|
|
|
|
|
|
return emailRegex.test(email);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 14:42:37 +01:00
|
|
|
function isIsoDate(value) {
|
|
|
|
|
assert.strictEqual(typeof value, 'string');
|
|
|
|
|
|
|
|
|
|
const date = new Date(value);
|
|
|
|
|
return !Number.isNaN(date.getTime());
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 15:43:24 +01:00
|
|
|
export default {
|
2026-02-16 14:42:37 +01:00
|
|
|
isEmail,
|
|
|
|
|
isIsoDate
|
2026-02-14 15:43:24 +01:00
|
|
|
};
|