如何创建约束以检查电子邮件在postgres中是否有效? [英] How can I create a constraint to check if an email is valid in postgres?
本文介绍了如何创建约束以检查电子邮件在postgres中是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在postgres中创建约束以使用正则表达式?
How can I create a constraint to use a regular expression in postgres?
推荐答案
CREATE TABLE emails (
email varchar
CONSTRAINT proper_email CHECK (email ~* '^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+$')
);
(正则表达式可能不完整,您可以在网络上搜索匹配电子邮件的正则表达式,然后选择您最喜欢的一个)。
(regex may be incomplete, you can search for regexp for email matching all over the web and pick the one you like best).
这篇关于如何创建约束以检查电子邮件在postgres中是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文