サーバレス練習帳

着眼大局着手小局

pythonの文字列フォーマットの比較

これでいけるっぽい。

import re
 
result = ""
input_tel1 = "03-1111-2222"
input_tel2 = "03-452-22234"
 
def check(tel):
    if re.match('[0-9]{2}-[0-9]{4}-[0-9]{4}', tel):
        return "OK"
    else:
        return "NG"
 
print("input_tel1{0}".format(check(input_tel1)))
print("input_tel2{0}".format(check(input_tel2)))

≪引用元≫

www.sejuku.net