使用验证器来限制存储 URL 的数据库字段的可接受域?

Using validators to constrain the acceptable domains for a db field that stores a URL?

我有一个 table 和一个应该存储有效 URL 的数据库字段,我想将允许的 URL 条目限制为三个或四个特定域(让我们例如,只允许 google.com、yahoo.com 和 bing.com)。

... Field('f_url', type='string', requires = IS_EMPTY_OR(IS_URL()), label=current.T('URL')), ... 

使用验证器指定 acceptable 域的最佳方式是什么?

您可以添加 IS_MATCH 验证器:

IS_EMPTY_OR([IS_URL(), IS_MATCH(r'google\.com$|yahoo\.com$|bing\.com$')])