Skip to content

Commit 4746097

Browse files
authored
Merge pull request #71 from AndrewThompson999/feature/email-regex
Update regex util
2 parents 5f18f73 + 4f288af commit 4746097

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/utils/regex.util.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@ export const buildLookaheadRegex = (tokens = []) => {
1111
const lookahead = tokens.map(t => `(?=.*\\b${t}\\b)`).join("");
1212
// keep it anchored (start) to reduce backtracking
1313
return new RegExp(`^${lookahead}.*$`, "i");
14-
};
14+
};
15+
16+
/**
17+
* Basic email validation (practical, not full RFC5322).
18+
* Returns true for common valid emails like "user@example.com".
19+
* Note: prefer sending a confirmation email for final verification.
20+
*/
21+
export const isEmail = (s = '') => {
22+
const re = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
23+
return re.test(String(s).trim());
24+
};

0 commit comments

Comments
 (0)