validateEmail
Description
It resolves the the string passed in the supposedStringEmailFormat parameter if it is a valid email. Rejects if string is not an email. The regex for validating the email is /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function validateEmail(supposedStringEmailFormat[, tuple]): Promise<string || Array> |
Examples
1
2
3
import { validateEmail } from "puddy-m/lib/validators/complexValidators";
validateEmail("foo@bar.com").then((validatedEmail) => console.log(validatedEmail)); // true
1
2
3
4
5
import { validateEmail } from "puddy-m/lib/validators/complexValidators";
validateEmail("foo@bar.com", [])
.then((tuple) => validateString("string", tuple))
.then((tuple) => console.log(tuple)); // ['foo@bar.com', 'string']
1
2
3
4
5
6
7
8
9
10
11
12
13
import { validateEmail } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const validatedEmail = await validateEmail("foo@bar.com");
console.log(validatedEmail); // prints "foo@bar.com"
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
import { validateEmail } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const validatedEmail = await validateEmail("This is not an email");
} catch (e) {
//Throws EmailValidationError
console.log(e);
}
};
run();