python 非法字符处理
生活随笔
收集整理的這篇文章主要介紹了
python 非法字符处理
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
有勇氣的牛排
官方地址: https://www.920vip.net/
過濾非法字符
def sql_filter(sql, max_length=20):dirty_stuff = ["\"", "\\", "/", "|", "&", "*", "'", "=", "-", "#", ";", "<", ">", "+", "%", "$", "(", ")", "%", "@","!"]for stuff in dirty_stuff:sql = sql.replace(stuff, "")return sql[:max_length]username = "1234567890!@#!@#!@#$%======$%|&***"username = sql_filter(username) # SQL注入 print(username)# 輸出結(jié)果是:1234567890檢測是否包含非法字符
import re# username = "1234567890!@#!@#!@#$%======$%|&***" username = "1234567890*"# 檢測到非法字符進(jìn)入if if not re.search(u'^[_a-zA-Z0-9\u4e00-\u9fa5]+$', username):msg = u"用戶名不可以包含非法字符(!,@,#,$,%...)"print(msg)參考:
https://www.cnblogs.com/cybermat/articles/473314.html
https://blog.csdn.net/weixin_30707875/article/details/99341309
總結(jié)
以上是生活随笔為你收集整理的python 非法字符处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 易语言---时间操作
- 下一篇: python 操作pdf