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 ...
随机推荐
- mongodb 学习笔记 09 -- shard分片
概述 shard 分片 就是 把不同的数据分在不同的server 模型 当中: 用户对mongodb的操作都是向mongs请求的 configsvr 用于保存,某条数据保存在哪个sha ...
- android81 多线程下载和断电续传
package com.itheima.multithreaddownload; import java.io.BufferedReader; import java.io.File; import ...
- C#实现Ruby的负数索引器
public class InvertibleList<T> : List<T> { public new T this[int index] { get { ) return ...
- Android开发之使用意图调用内置应用程序
意图可以调用活动,也常被用来调用内置应用程序,如加载web页面,拨号页面,内置地图应用等等.下面就用例子来说明该用法. 效果图如下: 实现代码如下: 上图中的启动MyBrowser是用意图来调用MyW ...
- CSS背景颜色、背景图片、平铺、定位、固定
CSS背景颜色设置 background-color:red;如设置背景颜色为红色: 背景颜色设置支持3种写法: 颜色名 16进制 rgb CSS背景图片颜色设置 background-image:u ...
- Ubuntu安装sar出错Please check if data collecting is enabled in /etc/default/sysstat
1.安装sysstat apt-get install sysstat 2.安装后无法使用: Cannot open /var/log/sysstat/sa02: No such file or di ...
- springmvc使用@ResponseBody返回json乱码解决方法
1.springmvc 3.2以上的版本解决乱码的方法: 第一步:在配置中加入: <mvc:annotation-driven> <mvc:message-converters re ...
- PHP 给前面或者后面添加0补位
相信大家一定遇到这样的问题,因为PHP是弱类型的,所以进行排序的时候,有时候很胃疼 所以这里就需要将位数进行统一后进行处理 一般都是将末尾添加0进行补位 方法1 : str_pad — 使用另一个字 ...
- jquery和js cookie的使用解析
JavaScript是运行在客户端的脚本,因此一般是不能够设置Session的,因为Session是运行在服务器端的.而cookie是运行在客户端的,所以可以用JS来设置cookie. 在这里分别通过 ...
- 自定义Operation
1.要自定义一个Operation 首先要创建一个继承于NSOperation的类. 2.在创建好的类的.h文件声明自定义的方法:-(instancetype)initWithDownLoadMess ...