pg_html5_email_address

验证Email是否符合HTML5规范的扩展

概览

扩展包名版本分类许可证语言
pg_html5_email_address1.2.3UTILPostgreSQLSQL
ID扩展名BinLibLoadCreateTrustReloc模式
4180pg_html5_email_address-
相关扩展pg_smtp_client url_encode pg_render gzip bzip zstd http pg_net

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY1.2.31817161514pg_html5_email_address-
RPMPIGSTY1.2.31817161514pg_html5_email_address_$v-
DEBPIGSTY1.2.31817161514postgresql-$v-pg-html5-email-address-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
el8.aarch64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
el9.x86_64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
el9.aarch64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
el10.x86_64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
el10.aarch64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
d12.x86_64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
d12.aarch64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
d13.x86_64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
d13.aarch64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
u22.x86_64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
u22.aarch64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
u24.x86_64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
u24.aarch64
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3
PIGSTY 1.2.3

构建

您可以使用 pig build 命令构建 pg_html5_email_address 扩展的 RPM / DEB 包:

pig build pkg pg_html5_email_address         # 构建 RPM / DEB 包

安装

您可以直接安装 pg_html5_email_address 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install pg_html5_email_address;          # 当前活跃 PG 版本安装
pig ext install -y pg_html5_email_address -v 18  # PG 18
pig ext install -y pg_html5_email_address -v 17  # PG 17
pig ext install -y pg_html5_email_address -v 16  # PG 16
pig ext install -y pg_html5_email_address -v 15  # PG 15
pig ext install -y pg_html5_email_address -v 14  # PG 14
dnf install -y pg_html5_email_address_18       # PG 18
dnf install -y pg_html5_email_address_17       # PG 17
dnf install -y pg_html5_email_address_16       # PG 16
dnf install -y pg_html5_email_address_15       # PG 15
dnf install -y pg_html5_email_address_14       # PG 14
apt install -y postgresql-18-pg-html5-email-address   # PG 18
apt install -y postgresql-17-pg-html5-email-address   # PG 17
apt install -y postgresql-16-pg-html5-email-address   # PG 16
apt install -y postgresql-15-pg-html5-email-address   # PG 15
apt install -y postgresql-14-pg-html5-email-address   # PG 14

创建扩展

CREATE EXTENSION pg_html5_email_address;

用法

pg_html5_email_address: PostgreSQL 的 HTML5 电子邮件地址验证

提供与 HTML5 <input type="email"> 规范一致的电子邮件地址验证。

域类型:html5_email

一个强制执行 HTML5 电子邮件验证规则的域类型,支持大小写不敏感比较:

SELECT 'user@example.com'::html5_email;

-- 大小写不敏感的相等比较:
SELECT 'User@Example.com'::html5_email = 'user@example.com'::html5_email;
-- t

-- 无效的电子邮件地址会触发 check_violation 错误:
SELECT 'user @example.com'::html5_email;
-- ERROR: check_violation

函数:html5_email_regexp()

返回匹配有效 HTML5 电子邮件地址的正则表达式:

-- 检查字符串是否为有效的 HTML5 电子邮件地址
SELECT 'user@example.com' ~ html5_email_regexp();
-- t

SELECT 'user @example.com' ~ html5_email_regexp();
-- f

使用可选的捕获组获取本地部分和域名部分:

SELECT (regexp_matches('user@example.com', html5_email_regexp(true)))[1];
-- 'user'
SELECT (regexp_matches('user@example.com', html5_email_regexp(true)))[2];
-- 'example.com'

验证规则

  • 不允许包含空格
  • 不允许使用非 ASCII 字符(本地部分和域名部分均不允许)
  • @ 后面必须有内容
  • 本地部分允许使用特殊字符,如 !#$%&'*+/=?^_{|}~-`

最后修改 2026-03-14: update extension metadata (953cbd0)