验证.edu或.ac电子邮件地址 [英] validate a .edu or .ac email address

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

问题描述

我是菜鸟,但是努力尝试简单地验证仅以 .edu或 .ac结尾的电子邮件地址,对于这个看似简单的问题是否有简单的功能/脚本/解决方案?能够使用php,javascript或jquery。

I'm a noob but trying vigorously to simply validate email addresses that only end in ".edu" or ".ac" is there a simple function/script/solution to this seemingly simple problem? able to use php,javascript or jquery.

任何帮助都会非常感谢!

Any help would be great thanks in advance!

推荐答案

您想要一个正则表达式。

You want a regular expression.

以下模式测试以.com等顶级域名结尾的任何电子邮件地址, .org,.net,.biz等。

The following pattern tests for any e-mail address ending in a top-level domain like .com, .org, .net, .biz etc.

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b

您可以在PHP中使用 preg_match函数,并将其作为模式,只需更改最后要接受的顶级域列表即可。如果函数返回0,则地址无效,如果返回1,则表明地址匹配。

You can use the preg_match function in PHP, pass this as the pattern, and just change the list of top-level domains you want to accept at the end. If the function returns 0, the address didn't validate, if it returns 1, it did match.

正则表达式源: http://www.regular-expressions.info/email.html

preg_match: http://php.net/manual/zh/function。 preg-match.php

preg_match: http://php.net/manual/en/function.preg-match.php

jQuery还具有验证插件具有用于验证电子邮件地址的内置模式,但是对于那些禁用Javascript的人,您需要将此与PHP的服务器端验证结合使用。

jQuery also has a validate plugin with built-in patterns for validating e-mail addresses, but you'd need to combine this with the server-side validation in PHP for those people that have Javascript disabled.

验证插件: http:// docs。 jquery.com/Plugins/Validation/validate

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆