Skip to content

Commit 4841237

Browse files
committed
feat: Email validations
1 parent eddf370 commit 4841237

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { isValid_Email } from '../email-validation';
2+
3+
describe('isValid_Email', () => {
4+
it('should return true for valid email addresses', () => {
5+
expect(isValid_Email('[email protected]')).toBe(true);
6+
expect(isValid_Email('[email protected]')).toBe(true);
7+
expect(isValid_Email('[email protected]')).toBe(true);
8+
});
9+
10+
it('should return false for invalid email addresses', () => {
11+
expect(isValid_Email('plainaddress')).toBe(false);
12+
expect(isValid_Email('@missingusername.com')).toBe(false);
13+
expect(isValid_Email('[email protected]')).toBe(false);
14+
expect(isValid_Email('username@com')).toBe(false);
15+
expect(isValid_Email('username@com.')).toBe(false);
16+
});
17+
18+
it('should return false for emails with spaces', () => {
19+
expect(isValid_Email('username@ example.com')).toBe(false);
20+
});
21+
22+
it('should return false for null or undefined inputs', () => {
23+
expect(isValid_Email(null as any)).toBe(false);
24+
expect(isValid_Email(undefined as any)).toBe(false);
25+
});
26+
27+
it('should return false for empty string', () => {
28+
expect(isValid_Email('')).toBe(false);
29+
});
30+
});

src/email-validation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const isValid_Email = (email: string): boolean => {
2+
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3+
return re.test(email);
4+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './aadhaar-validation';
2+
export * from './email-validation'
23
export * from './ssn-validation';

0 commit comments

Comments
 (0)