判断提交的表单中是否包含中文字

作者:半瓶墨水 链接:http://www.2maomao.com/blog/python-chinese-encode/

Some Chinese Please是用php写的wordpress插件。
基本原理是:英文spammer比较多,如果评论中没有中文字默认为spammer

上网查了一下Python做这个的代码,逻辑比较复杂,想了想,做了个判断是否包含非英语文字的:

str = comment.encode('utf-8')
if len(str) == len(comment):
    
raise forms.ValidationError('评论中必须包含中文字')

应该有作用。

  • Share/Bookmark

共 2 条评论

  • VespertineR 四月 15th, 2008 6:58 下午

test通过- -

@VespertineR
啥意思?呵呵我没有在这个blog上应用python的那个方法呀。

发表评论

  • :l
  • :)
  • :q
  • :(
  • :^
  • :x
  • :v
  • :D
  • :s
  • :h
  • :e
  • :X
  • :k
  • :w
  • :d
  • :p

注意:评论中需包含至少一个中文字,否则视为无效

Additional comments powered by BackType