如何驗證郵件標識是使用javascript/jquery/regex的gmail標識。使用JavaScript和Jquery驗證Gmail標識
對於eaxample:
我給[email protected]
。我需要檢查該郵件ID是一個Gmail ID或沒有? 我該怎麼做?
如何驗證郵件標識是使用javascript/jquery/regex的gmail標識。使用JavaScript和Jquery驗證Gmail標識
對於eaxample:
我給[email protected]
。我需要檢查該郵件ID是一個Gmail ID或沒有? 我該怎麼做?
if (/@gmail\.com$/.test(string)) {
// This is a gmail id.
}
試試這個
if (/^([A-Za-z0-9_\-\.])+\@([gmail|GMAIL])+\.(com)$/.test(yourstring)) {
// Valid gmail id.
}
使用正則表達式
[a-zA-Z0-9]+\@gmail.com
使用的ASCII碼進行驗證無正則表達式
<!DOCTYPE html>
<html>
<head>
<title>VALIDATION GMAIL ID ONLY</title>
<meta charset="utf-8">
<style>
body{
margin:0px;
padding:0px;
}
#box{
background-color:aquamarine;
height:300px;
width:700px;
margin:auto;
}
#box label{
font-size:30px;
margin-top:80px;
float:left;
font-family:arial;
color:#2b3b08;
font-weight: bold;
margin-left:40px;
}
#box input{
margin-top:72px;
width:350px;
height:40px;
border:2px solid black;
margin-left:20px;
}
#box p{
margin-left:150px;
font-size:19px;
}
#btn1{
border:none;
background-color:orange;
color:white;
padding:10px;
width:200px;
height:40px;
font-size:20px;
}
#btn1:hover{
cursor:pointer;
}
b{
font-size:20px;
color:red;
display:none;
}
</style>
</head>
<body>
<div id="box">
<label for="email">Email :</label>
<input type="email" name="email1" id="email" placeholder=" Enter Email Address " title="PLEASE ENTER YOUR OWN EMAIL">
<br clear="all">
<p>* Please Enter Only Gmail-email-address</p>
<center><button type="submit" id="btn1">Submit</button></center>
<br>
<center><b id="demo"></b></center>
</div>
<script>
var btn1=document.getElementById("btn1");
btn1.addEventListener('click',verify1);
function verify1()
{
var email=document.getElementById("email");
var email_value=document.getElementById("email").value;
var email_length=email_value.length;
var atindex=email_value.indexOf('@');
var dotindex=email_value.indexOf('.');
var mindex=email_value.lastIndexOf('m');
if(email_length=="")
{
document.getElementById("demo").style.display="block";
document.getElementById("demo").innerHTML="EMAIL ADDRESS IS REQUIRED";
}
else
{
if(atindex<5||dotindex-atindex!=6||mindex-dotindex!=3)
{
document.getElementById("demo").style.display="block";
document.getElementById("demo").innerHTML="PLEASE ENTER Valid Email";
}
else{
if(email_value.charCodeAt(atindex+1)!=71&&email_value.charCodeAt(atindex+1)!=103||email_value.charCodeAt(atindex+2)!=109&&email_value.charCodeAt(atindex+2)!=77||email_value.charCodeAt(atindex+3)!=65&&email_value.charCodeAt(atindex+3)!=97||email_value.charCodeAt(atindex+4)!=105&&email_value.charCodeAt(atindex+4)!=73||email_value.charCodeAt(atindex+5)!=76&&email_value.charCodeAt(atindex+5)!=108)
{
document.getElementById("demo").style.display="block";
document.getElementById("demo").innerHTML="PLEASE ENTER ONLY GMAIL-ID";
}
else
{
`document.getElementById("demo").style.display="none";`
}
}
}
}
</script>
</body>
'mindex'的用途是什麼?爲什麼'atindex <5'或'dotindex-atindex!= 6'的意思是'無效的電子郵件'('me @ localhost'完全有效)? – Toto 2017-08-13 17:50:16
ATINDEX意味着獲得'@'的位置,DOTINDEX意味着獲得''位置。 DOT MINDEX MEAN獲得'M'的位置我可以申請條件,因爲如果我們可能會丟失M,@或DIT(。),那麼它顯示的錯誤信息無效發送域名必須與[email protected]或XYZ @ GMAIL.COM – 2017-08-15 07:05:14
有用http://stackoverflow.com/questions/6205519/looking-for-a-regex-to-match-a-gmail-plus-address,http://stackoverflow.com/questions/8218345/regular-expression- gmail-com-or-start-with-1234-is-any-or-possi – elclanrs 2012-02-13 06:51:51
gmail是什麼意思?我的電子郵件是[email protected],它是一個Gmail賬戶 – lvil 2012-02-13 07:23:45
請記住在ID中加號。當網站告訴我我提供的地址是無效的時候,我非常討厭它。 – curial 2012-02-13 10:13:40