python判断用户注册中用户名是否包含非法字符
class UserRegisterForm(ModelForm):
role = forms.IntegerField()
check_password = forms.CharField(required=True) # 用户的密码验证 def clean(self):
cleaned_data = super(UserRegisterForm, self).clean()
# 检查用户的唯一性
if 'username' in cleaned_data:
username = cleaned_data['username']
if User.objects.filter(username=username).count() > 0:
msg = u"此用户已被注册!!。"
self._errors["username"] = self.error_class([msg]) del cleaned_data["username"] if not re.search(u'^[_a-zA-Z0-9\u4e00-\u9fa5]+$', username):
msg = u"用户名不可以包含非法字符(!,@,#,$,%...)"
self._errors['username'] = self.error_class([msg])
del cleaned_data['username'] # if "username" in cleaned_data:
# user_name = cleaned_data['username']
#
# # 判断用户名是否包含非法字符
# if not re.search(u'^[_a-zA-Z0-9\u4e00-\u9fa5]+$', user_name):
# msg = u"用户名包含了非法字符"
# self._errors['user_name'] = self.error_class([msg])
# del cleaned_data['username'] if 'password' in cleaned_data and 'check_password' in cleaned_data:
password = cleaned_data['password']
check_password = cleaned_data['check_password'] if len(password) < 6 or len(check_password) < 6:
msg = u'密码太简单!(建议密码长度为6-18位!)' self._errors['password'] = self.error_class([msg])
self._errors['check_password'] = self.error_class([msg]) del cleaned_data['password']
del cleaned_data['check_password'] if 'password' in cleaned_data and 'check_password' in cleaned_data:
password = cleaned_data['password']
check_password = cleaned_data['check_password']
if password != check_password:
msg = u'两次输入的密码不配配!' self._errors['password'] = self.error_class([msg])
self._errors['check_password'] = self.error_class([msg]) del cleaned_data['password']
del cleaned_data['check_password'] if 'password' in cleaned_data and 'check_password' in cleaned_data:
password = cleaned_data['password']
check_password = cleaned_data['check_password']
if password is u'' or check_password is u'':
msg = u'密码不可以为空!'
self._errors['password'] = self.error_class([msg])
self._errors['check_password'] = self.error_class([msg]) del cleaned_data['password']
del cleaned_data['check_password'] if 'mobile' in cleaned_data:
mobile = cleaned_data['mobile']
if mobile.isdigit():
if len(mobile) != 11:
msg = u"请输入正确的手机号码!例如:15925087562"
self._errors['mobile'] = self.error_class([msg]) del cleaned_data['mobile'] # 用户注册邮箱验证试用Django的认证方式
# if 'email' in cleaned_data:
# email = cleaned_data['email']
# if len(email) > 7:
# if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) == None:
# msg = u"请输入正确的邮箱地址,例如:xxxxxx@163.com"
# self._errors = self.error_class([msg])
#
# del cleaned_data['email'] return cleaned_data def __init__(self, *args, **kwargs):
super(UserRegisterForm, self).__init__(*args, **kwargs) class Meta:
model = User
fields = ('username', 'password', 'full_name', 'email', 'mobile')

python判断用户注册中用户名是否包含非法字符的更多相关文章
- Base64 报错 的解决办法 (Base-64 字符数组或字符串的长度无效。, 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。)
Base64 报错 的解决办法, 报错如下:1. FormatException: The input is not a valid Base-64 string as it contains a n ...
- SQL判断某列中是否包含中文字符或者英文字符
SQL判断某列中是否包含中文字符或者英文字符 [sql] select * from 表名 where 某列 like '%[吖-座]%' select * from 表名 where ...
- FromBase64String 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符
js前台: <input id="upload_img_input" v-on:change="onFileChange" type="file ...
- 小程序码B接口生成出错:场景内容包含非法字符
由于包含了非法字符,微信返回的字节不超过100字符,但是没有包含提示内容,因此很难识别发现问题所在
- SQL判断某列中是否包含中文字符、英文字符、纯数字 (转)
一.包含中文字符 select * from 表名 where 列名 like '%[吖-座]%' 二.包含英文字符 select * from 表名 where 列名 like '%[a-z]%' ...
- java判断A字符串中是否包含B字符
java.lang.String类提供的方法 public boolean contains(CharSequence s) 当且仅当此字符串包含指定的 char 值序列时,返回 true. 例如: ...
- [leetcode]242. Valid Anagram判断两个字符串是不是包含相同字符的重排列
/* 思路是判断26个字符在两个字符串中出现的次数是不是都一样,如果一样就返回true. 记住这个方法 */ if (s.length()!=t.length()) return false; int ...
- 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符
正常URL: http://localhost:16990/GoodsOrder/OrderRevoke.aspx??6G5lFi6xuoiLDhfOOOIkBYwy8RGpkfuza2gLlJrlT ...
- 判断数组(array)中是否包含某个字符(contains)
$a="a","","b" $a -contains "a" 返回 $true $a -notcontains &quo ...
随机推荐
- FZU 2129 子序列个数 (动态规划)
题意:子序列的定义:对于一个序列a=a[1],a[2],......a[n].则非空序列a'=a[p1],a[p2]......a[pm]为a的一个子序列,其中1<=p1<p2<.. ...
- Linux下jvm、tomcat、mysql、log4j优化配置笔记[转]
小菜一直对操作系统心存畏惧,以前也很少接触,这次创业购买了Linux云主机,由于木有人帮忙,只能自己动手优化服务器了.... 小菜的云主机配置大致为:centeos6(32位),4核心cpu,4G内存 ...
- Android Studio使用SVN,与eclipse共同开发。
Android Studio(下称AS)开发工具目前已经迅速在世界普遍使用起来,而在很多一部分公司内部,仍然有部分老员工坚持使用eclipse + SVN,而不改用AS,这使得想使用AS的小伙伴们都深 ...
- JS获取图片上传地址
function getObjectURL(file) { var url = null ; if (window.createObjectURL!=undefined) { // basic url ...
- Java Post 数据请求和接收
这两天在做http服务端请求操作,客户端post数据到服务端后,服务端通过request.getParameter()进行请求,无法读取到数据,搜索了一下发现是因为设置为text/plain模式才导致 ...
- Oracle中not exists 与not in 的使用情况
1.在oracle11g以上版本,oracle已经做了优化,能够自动将in优化成exists方式,因此oracle11g以上版本,使用in和exists效果是一样的. 2.在oracle中,使用not ...
- python 函数初识和文件操作
文件操作 打开文件:文件句柄 = open('文件路径', '模式') 打开文件的模式 w #以写的方式打开 (不可读,不存在则创建,存在则删除内容) a #以追加的模式打开(可读, 不存在则创建 ...
- SharePoint Dialog 使用
SharePoint中弹出模态窗口对体验提高太大了 方法为: 父页面中调用子页面: function showDialog() { var options = { ...
- Ajax无刷新提交表单和显示
ajax无刷新表单提交: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...
- Java-Android 之动画的实现
一:显示隐藏动画 在res目录下创建一个anim目录,然后在里面创建一个alpha.xml文件 <?xml version="1.0" encoding="utf- ...