Postgres函数验证电子邮件地址

Postgres函数验证电子邮件地址

本文介绍了Postgres函数验证电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查约束(该约束会调用一个函数来验证电子邮件地址)对我而言无法正常工作。

A check constraint which would call a function to validate email addresses is not working fine for me.

CREATE OR REPLACE FUNCTION f_IsValidEmail(text) returns BOOLEAN AS
'select $1 ~ ''^[^@\s]+@[^@\s]+(\.[^@\s]+)+$'' as result
' LANGUAGE sql;



SELECT f_IsValidEmail('[email protected]');

该函数返回false,应该为true。我已经尝试了其他一些正则表达式,但没有成功。谁能指出此功能的问题吗?

The function is returning false, which should be true. I have tried a couple of other regexs but in vain. Can anyone point out what's wrong with this function?

推荐答案

在为此付出很多努力之前,您要做的是确保您没有踢出有效的电子邮件地址。电子邮件地址中有各种各样的疯狂规则,如果您输入错误或错误的信息,那么使用正确的电子邮件地址的用户可能会被系统拒绝。

Before you go putting a lot of effort into this, the thing you want to do is make sure you're not kicking out valid email addresses. There's all kinds of insane rules for can or can't be in an email address, and if you get it wrong, in the wrong direction, a user with a perfectly valid email address might get rejected by your system.

确定电子邮件地址是否有效的最佳方法是将其用作需要电子邮件的注册过程的一部分。任何其他事情都是很多工作,却没有什么收获。

The best way to determine if an email address is valid is to use it as part of a registration process where email is REQUIRED. Anything else is a lot of work for little gain.

这篇关于Postgres函数验证电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 13:00