python Regex判斷郵箱格式是否正確,pythonRegex

來源:互聯網
上載者:User

python Regex判斷郵箱格式是否正確,pythonRegex
import re

def validateEmail(email):

    if len(email) > 7:
        if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None:
            return 1
    return 0
Python怎判斷Regex是否匹配成功

直接匹配就行,匹配不成功,會返回None,成功則返回成功的匹配對象。
如:
if pat.match(‘a’)
print ‘match’
如果匹配了'a',則會輸出match,否則if 條件不成立,也就什麼都不輸出。

你不要用=='None', None本來就是False
直接
if s:
print 1 #匹配成功
else:
print 2 #匹配失敗
 
編寫一個驗證郵箱地址格式正確性的Regex,並解釋Regex的含義答案要快,情況緊急!!!

JS中這樣寫
var CheckMail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
var email = document.getElementById( "email" );
if(!CheckMail.test(email))
{
alert("email格式不對!"); return false;
}
真正含意不想多說正則這東西。說了也只會一知半解!
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.