10 examples of 'simple email validation in javascript' in JavaScript

Every line of 'simple email validation in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
10function validateEmail (email) {
11 if (email && email.match(/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i)) {
12 return true
13 }
14
15 return false
16}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

20function validate_email(email)
21{
22 var emailReg = /\S+@\S+\.\S+/;
23
24 if(!emailReg.test(email)) {
25 return false;
26 }
27
28 return true;
29}
209function validateEmail(emailTest) {
210 var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
211 if (filter.test(emailTest) && emailTest.length < 99) {
212 return true;
213 } else {
214 return false;
215 }
216}
8function validateEmail (val) {
9 return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(val);
10}
236function isValidEmail(value) {
237 var regEx = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
238 return (value && value.length !== 0 && regEx.test(value))
239}
32function validateEmail(email, callback) {
33 callback = callback || function() {};
34 var email_notify = $('#email-notify');
35
36 if (!email) {
37 validationError = true;
38 return;
39 }
40
41 if (!utils.isEmailValid(email)) {
42 showError(email_notify, '[[error:invalid-email]]');
43 return;
44 }
45
46 socket.emit('user.emailExists', {
47 email: email
48 }, function(err, exists) {
49 if(err) {
50 return app.alertError(err.message);
51 }
52
53 if (exists) {
54 showError(email_notify, '[[error:email-taken]]');
55 } else {
56 showSuccess(email_notify, successIcon);
57 }
58
59 callback();
60 });
61}
1export default function validateEmail(email: string) {
2 // tslint:disable-next-line:max-line-length
3 const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
4 return reg.test(email) && email !== '' && email.length > 0;
5}
17function validateEmail(email) {
18 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
19 return re.test(String(email).toLowerCase());
20}
12function checkEmail(scope, name) {
13 if(!emailPattern.test(scope[name])) {
14 scope[name].Err = true;
15 scope[name].Msg = 'Not an email address';
16 return false;
17 } else {
18 return true;
19 }
20}
225function validateEmail(email) {
226 if (email.length <= 0) {
227 return false;
228 }
229 var emailPattern = /\S+@\S+\.\S+/;
230 return emailPattern.test(email);
231}

Related snippets