📜  django regexvalidator 示例 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:00.643000             🧑  作者: Mango

代码示例2
# for outside model uses
from django.core.validators import RegexValidator

validate_alphanumeric = RegexValidator(r'^[a-zA-Z0-9]*$', 'Only alphanumeric characters are allowed.')
validate_alphanumeric("foo") # ok, nothing happens
validate_alphanumeric("++") # raises a ValidationError

ValidationError: [u'Only alphanumeric characters are allowed.']