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 ...
随机推荐
- pcap 安装(debian7 linux) qt 使用pcap.h
安装方法一.sudo apt-get install libpcap-dev 安装方法二. 去http://www.tcpdump.org/下载最新的libpcap.tar.gz包 解压以后 ./co ...
- Memcached Java Client with sample program--reference
In my previous post, I listed down most common telnet commands for memcached with sample execution t ...
- hdu2034java
人见人爱A-B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 今天给大家分享一下Android中的资源与国际化的问题
摘要:该文章将向大家分享Android中的资源与国际化的问题. 今天给大家分享一下Android中的资源与国际化的问题,通常我们新建一个Android工程,目录结构如下图所示: 我们主要看一下layo ...
- Objective-C:内存管理
1 传统内存管理 Objective-C对象的生命周期可以分为:创建.存在.消亡. 1.1 引用计数 类似Java,Objective-C采用引用计算(reference counting)技术来管理 ...
- ashx+html+ajax
HTML: $(function() { ajax("NewsList.ashx", function(resText) { document.getElementById(&qu ...
- 各种SQL类型
一.SQL:通常我们说的sql指的是最古老运用最方法的结构化查询语言(Structured Query Language),大部分人接触最多的是数据库查询使用,关系型数据库基本都支持. 二.T-SQL ...
- 给右键 添加dos命令
reg add "HKEY_CURRENT_USER\Console" /v "ScreenBufferSize" /t REG_DWORD /d 655361 ...
- 状态CSS
<span style="background-color: #999999 !important;color:#FFFFFF;font-size: 11px;height: 18px ...
- Oracle学习【语句查询】
基本查询语句any和all不能单独使用,必须和比较符一起使用>any 大于最小的例如:select * from emp where sal >any(1000,2000);<any ...