亚洲精品久久久久久第一页-人妻少妇精彩视品一区二区三区-91国产自拍免费视频-免费一级a在线播放视频正片-少妇天天日天天射天天爽-国产大屁股喷水视频在线观看-操美女骚穴抽插性爱视频-亚洲 欧美 中文字幕 丝袜-成人免费无码片在线观看

郵箱綁定手機(jī)號步驟 驗(yàn)證郵箱地址是什么意思


郵箱綁定手機(jī)號步驟 驗(yàn)證郵箱地址是什么意思

文章插圖
在用戶提交郵箱地址以后我們需要驗(yàn)證用戶郵箱地址是否合法,解決方案的范圍很廣,可以通過使用正則表達(dá)式來檢查電子郵件地址的格式是否正確,甚至可以通過嘗試與遠(yuǎn)程服務(wù)器進(jìn)行交互來解決問題 。兩者之間也有一些中間立場,例如檢查頂級域是否具有有效的MX記錄以及檢測臨時(shí)電子郵件地址 。
一種確定的方法是向該地址發(fā)送電子郵件,并讓用戶單擊鏈接進(jìn)行確認(rèn) 。但是在發(fā)送文章之前我們需要對用戶的郵箱進(jìn)行預(yù)定義檢測 。
簡單版本:正則表達(dá)式基于W3C的正則表達(dá)式,此代碼檢查電子郵件地址的結(jié)構(gòu) 。
package mainimport ("fmt""regexp")var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")func main() {// Valid examplee := "test@golangcode.com"if isEmailValid(e) {fmt.Println(e + " is a valid email")}// Invalid exampleif !isEmailValid("just text") {fmt.Println("not a valid email")}}// isEmailValid checks if the email provided passes the required structure and length.func isEmailValid(e string) bool {if len(e) < 3 && len(e) > 254 {return false}return emailRegex.MatchString(e)}稍微更好的解決方案:Regex + MX查找在此示例中,我們結(jié)合了對電子郵件地址進(jìn)行正則表達(dá)式檢查的快速速度和更可靠的MX記錄查找 。這意味著,如果電子郵件的域部分不存在,或者該域不接受電子郵件,它將被標(biāo)記為無效 。
作為net軟件包的一部分,我們可以使用LookupMX為我們做額外的查找 。
package mainimport ("fmt""net""regexp""strings")var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")func main() {// Made-up domainif e := "test@golangcode-example.com"; !isEmailValid(e) {fmt.Println(e + " is not a valid email")}// Real domainif e := "test@google.com"; !isEmailValid(e) {fmt.Println(e + " not a valid email")}}// isEmailValid checks if the email provided passes the required structure// and length test. It also checks the domain has a valid MX record.func isEmailValid(e string) bool {if len(e) < 3 && len(e) > 254 {return false}if !emailRegex.MatchString(e) {return false}parts := strings.Split(e, "@")mx, err := net.LookupMX(parts[1])if err != nil || len(mx) == 0 {return false}return true}


    以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請您及時(shí)就醫(yī)或請專業(yè)人士給予相關(guān)指導(dǎo)!

    「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對您有所幫助: