email = 1*( atext / "." ) "@" label *( "." label )label = let-dig [ [ ldh-str ] let-dig ] ; limited to a length of 63 characters by RFC 1034 section 3.5atext = < as defined in RFC 5322 section 3.2.3 >let-dig = < as defined in RFC 1034 section 3.5 >ldh-str = < as defined in RFC 1034 section 3.5 >
function validateEmail(email) {var re = /\S+@\S+\.\S+/;return re.test(email);}
console.log(validateEmail('my email is anystring@anystring.any')); // true
console.log(validateEmail('my email is anystring@anystring .any')); // false
function isEmail(email) {return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(email);}
像这样使用:
if (isEmail('youremail@yourdomain.com')){ console.log('This is email is valid'); }
function validateEmail(email){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,}))$/;return re.test(email);}
var emailCheck=/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;console.log( emailCheck.test('some.body@domain.co.uk') );
// This is a fairly naive implementation, but it covers 99% of use cases.// For more details, see http://en.wikipedia.org/wiki/Email_address#Syntax// TODO(mariakhomenko): we should also be handling i18n domain names as per// http://en.wikipedia.org/wiki/Internationalized_domain_name
<pre>**The personal_info part contains the following ASCII characters.1.Uppercase (A-Z) and lowercase (a-z) English letters.2.Digits (0-9).3.Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~4.Character . ( period, dot or fullstop) provided that it is not the first or last character and it will not come one after the other.**</pre>*Example of valid email id*<pre>yoursite@ourearth.commy.ownsite@ourearth.orgmysite@you.me.netxxxx@gmail.comxxxxxx@yahoo.com</pre><pre>xxxx.ourearth.com [@ is not present]xxxx@.com.my [ tld (Top Level domain) can not start with dot "." ]@you.me.net [ No character before @ ]xxxx123@gmail.b [ ".b" is not a valid tld ]xxxx@.org.org [ tld can not start with dot "." ].xxxx@mysite.org [ an email should not be start with "." ]xxxxx()*@gmail.com [ here the regular expression only allows character, digit, underscore and dash ]xxxx..1234@yahoo.com [double dots are not allowed</pre>**javascript mail code**
function ValidateEmail(inputText){var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;if(inputText.value.match(mailformat)){document.form1.text1.focus();return true;}else{alert("You have entered an invalid email address!");document.form1.text1.focus();return false;}}
var isEmail = $compile('<input ng-model="m" type="email">')($rootScope.$new()).controller('ngModel').$validators["email"];
if (isEmail('email@gmail.com')) {console.log('valid');}
function doesEmailExist(email) {var emailExistence = require('email-existence');return emailExistence.check(email,function (err,status) {if (status) {return status;}else {throw new Error('Email does not exist');}});}
function validateEmail(email) {var re = /^[a-z][a-zA-Z0-9_.]*(\.[a-zA-Z][a-zA-Z0-9_.]*)?@[a-z][a-zA-Z-0-9]*\.[a-z]+(\.[a-z]+)?$/;return re.test(email);}
function validMail(mail){return /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()\.,;\s@\"]+\.{0,1})+([^<>()\.,;:\s@\"]{2,}|[\d\.]+))$/.test(mail);}
let val = 'email@domain.com';if(/^[a-z0-9][a-z0-9-_\.]+@([a-z]|[a-z0-9]?[a-z0-9-]+[a-z0-9])\.[a-z0-9]{2,10}(?:\.[a-z]{2,10})?$/.test(val)) {console.log('passed');}
The local-part of the email address may use any of these ASCII characters:
- uppercase and lowercase Latin letters A to Z and a to z;- digits 0 to 9;- special characters !#$%&'*+-/=?^_`{|}~;- dot ., provided that it is not the first or last character unless quoted, and provided also that it does not appear consecutively unless quoted (e.g. John..Doe@example.com is not allowed but "John..Doe"@example.com is allowed);[6]Note that some mail servers wildcard local parts, typically the characters following a plus and less often the characters following a minus, so fred+bah@domain and fred+foo@domain might end up in the same inbox as fred+@domain or even as fred@domain. This can be useful for tagging emails for sorting, see below, and for spam control. Braces { and } are also used in that fashion, although less often.- space and "(),:;<>@[\] characters are allowed with restrictions (they are only allowed inside a quoted string, as described in the paragraph below, and in addition, a backslash or double-quote must be preceded by a backslash);- comments are allowed with parentheses at either end of the local-part; e.g. john.smith(comment)@example.com and (comment)john.smith@example.com are both equivalent to john.smith@example.com.
// First way.
try {EmailValidator.validate('balovbohdan@gmail.com');} catch (e) {console.error(e.message);}
// Second way.
const email = 'balovbohdan@gmail.com';const isValid = EmailValidator.validateKind(email);
if (isValid)console.log(`Email is valid: ${email}.`);elseconsole.log(`Email is invalid: ${email}.`);
import {C,Streams} from '@masala/parser'
const illegalCharset = ' @\u00A0\n\t';const extendedIllegalCharset = illegalCharset + '.';
// Assume 'nicolas@internal.masala.co.uk'export function simpleEmail() {
return C.charNotIn(illegalCharset).rep() // 'nicolas'.then(C.char('@')).then(subDns()) //'internal.masala.co.'.then(C.charNotIn(extendedIllegalCharset).rep()) //'uk'.eos(); // Must be end of the char stream}
// x@internal.masala.co.uk => extract 'internal.masala.co.'function subDns() {return C.charNotIn(extendedIllegalCharset).rep().then(C.char('.')).rep()}
function validateEmail(email:string) {console.log(email + ': ' + (simpleEmail().parse(Streams.ofString(email)).isAccepted()));}
validateEmail('nicolas@internal.masala.co.uk'); // TruevalidateEmail('nz@co.'); // False, trailing "."
如果您想接受最终丑陋的电子邮件版本,您可以在第一部分中添加引号:
function inQuote() {return C.char('"').then(C.notChar('"').rep()).then(C.char('"'))}
function allEmail() {
return inQuote().or(C.charNotIn(illegalCharset)).rep() // repeat (inQuote or anyCharacter).then(C.char('@')).then(subDns()).then(C.charNotIn(extendedIllegalCharset).rep()).eos() // Must be end of the character stream// Create a structure.map(function (characters) { return ({ email: characters.join('') }); });}
// Html form call function name at submit button
<form name="form1" action="#"><input type='text' name='text1'/><input type="submit" name="submit" value="Submit"onclick="ValidateEmail(document.form1.text1)"/></from>
// Write the function name ValidateEmail below
<script>function ValidateEmail(inputText){var mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;if(inputText.value.match(mailformat)){alert("Valid email address!");document.form1.text1.focus();return true;}else{alert("You have entered an invalid email address!");document.form1.text1.focus();return false;}}</script>
var email = 'hello@example.com'if(email.split('@').length == 2 && email.indexOf('.') > 0){// The split ensures there's only 1 @// The indexOf ensures there's at least 1 dot.}