Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在web2py数据结构中设置为非空和字符串(不包括0-9)_Python_Web2py_Web2py Modules - Fatal编程技术网

Python 如何在web2py数据结构中设置为非空和字符串(不包括0-9)

Python 如何在web2py数据结构中设置为非空和字符串(不包括0-9),python,web2py,web2py-modules,Python,Web2py,Web2py Modules,我正在pythonanywhere.com中开发web2py-Models-db_testing.py 以下代码正在成功运行: #-*-编码:utf-8-*- db=DAL('sqlite://storage.sqlite') db.define_表(“注册”, 字段('firstname',requires=不为空(错误消息='Should NOT blank'), 字段('lastname',requires=不是空的(), 字段('gender',requires=在集合中(['Male

我正在pythonanywhere.com中开发web2py-Models-db_testing.py

以下代码正在成功运行:

#-*-编码:utf-8-*-
db=DAL('sqlite://storage.sqlite')
db.define_表(“注册”,
字段('firstname',requires=不为空(错误消息='Should NOT blank'),
字段('lastname',requires=不是空的(),
字段('gender',requires=在集合中(['Male','Female']),
字段(“生日”、“日期”),
字段('email',requires=IS\u email(error\u message='invalid email!')),
字段('salary','integer'),
字段('资历','整数')

)
要检查它是否是字符串:
如果是实例(firstname,str)

要检查是否为非空:如果firstname!='',则可以执行
如果firstname
;在Python中,空对象在用作布尔值时被视为“False”。要检查它是否为字母字符,可以执行
if firstname.isalpha()

如中所述,
字段的
属性可以是验证程序列表。所以,你可以这样做:

Field('firstname', requires=[IS_NOT_EMPTY(), IS_ALPHANUMERIC()])
若要仅限于字母,请将
IS_MATCH
与正则表达式一起使用:

Field('firstname', requires=[IS_NOT_EMPTY(), IS_MATCH('^[a-zA-Z]+$')])

如上所述,您不一定需要
IS not_EMPTY
验证器,因为
IS MATCH
中的正则表达式至少需要一个字母,但您可能希望保留
IS not_EMPTY
以便为空响应显示不同的错误消息。

如何设置和组合str和=“”在web2py数据结构中?是字母数字()包括a-z、a-z和0-9。是否可以排除0-9?请参阅更新的答案。书中记录了所有的验证器: