JavaScript判斷Email位址是否有效

2021-04-12 22:54:48 字數 1604 閱讀 3037

在用asp編寫頁面時,如果涉及到郵件傳送,一般會要求輸入email位址。錯誤的email位址往往帶來許多不必要的麻煩,用下面的函式isvalidemail就能判斷出乙個email位址是否有效。

函式源**:

<%

function isvalidemail(email)

validflag = false

if (email <> "") and (instr(1, email, "@") > 0) and (instr(1, email, ".") > 0) then

atcount = 0

specialflag = false

for atloop = 1 to len(email)

atchr = mid(email, atloop, 1)

if atchr = "@" then atcount = atcount + 1

if (atchr >= chr(32)) and (atchr <= chr(44)) then specialflag = true

if (atchr = chr(47)) or (atchr = chr(96)) or (atchr >= chr(123)) then specialflag = true

if (atchr >= chr(58)) and (atchr <= chr(63)) then specialflag = true

if (atchr >= chr(91)) and (atchr <= chr(94)) then specialflag = true

next

if (atcount = 1) and (specialflag = false) then

badflag = false

tary1 = split(email, "@")

username = tary1(0)

domainname = tary1(1)

if (username = "") or (domainname = "") then badflag = true

if mid(domainname, 1, 1) = "." then badflag = true

if mid(domainname, len(domainname), 1) = "." then badflag = true

validflag = true

end if

end if

if badflag = true then validflag = false

isvalidemail = validflag

end function

%>

用法舉例:

isvalidemail("[email protected]") 返回ture

isvalidemail("[email protected]") 返回ture

isvalidemail("myemail263.net") 返回false

isvalidemail("my_263_email@263) 返回false

請注意,函式只是判斷email位址格式是否有效,但並不能檢查該位址是否確實存在。  

EMA與MA 理解公式演算法 EMA與MA

計算 有一組資料 價為 1,2,3,4,5,6,7,求其ema c,5 解答 對應上面資料,x1,x2,x3,x4,x5分別對應3 4 5 6 7 則ema c,5 5 15 x5 4 15 x4 3 15 x3 2 15 x2 1 15 x1 5 x5 4 x4 3 x3 2 x2 1 x1 15...

JavaScript 條件判斷(if)

使用者輸入資訊 var y window.prompt 請輸入年 var m window.prompt 請輸入月 var d number prompt 請輸入天 後台判斷 是否為閏年 var isrun y 4 0 y 100 0 y 400 0 建立乙個變數來收集天數 var days 0 判...

android Intent傳送文字email

如下 import android.content.intent import android.os.bundle import android.view.view import android.view.view.onclicklistener import android.widget.butt...