验证字符串是否为 FQDN (Codeigniter)
我正在尝试使用 form_validation 使用自定义运行来验证域名:
function fqdn($str)
{
$CI =& get_instance();
$CI->form_validation->set_message('fqdn','The %s is not a valid domain name.');
$re1='((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])';
if ($c=preg_match_all ("/".$re1."/is", $str, $matches)){
return TRUE;
}
else{
return FALSE;
}
}
除了我不希望它在地址中的任何位置以及存在 @
的地方返回 true 之外,它的工作效果相对较好前导或尾随 -
我将如何更改代码以匹配。
另外,如果我应该做其他事情,这样我就可以确保分机是正确的,而不是一些编造的垃圾,那么我是否将这一切都错了。
感谢您抽出时间。
I'm trying to use form_validation to validate a domain name using a custom run:
function fqdn($str)
{
$CI =& get_instance();
$CI->form_validation->set_message('fqdn','The %s is not a valid domain name.');
$re1='((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])';
if ($c=preg_match_all ("/".$re1."/is", $str, $matches)){
return TRUE;
}
else{
return FALSE;
}
}
This works relatively well apart from I dont want it to return true if there are @
anywhere in the address and also where there are leading or trailing -
How would I go about changing the code to match.
Also am I going about this all wrong should there be something else I should be doing so I can make sure that the ext are correct and not some made up garbage.
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我用的这个
不是我自己做的,而是取自 FQDN正则表达式并进行了一些编辑,使其不仅仅匹配主机名,例如。 我的主机
另请注意,它不匹配反向域名,如 123.213.in-addr.arpa,
它会匹配任何 TLD,甚至是那些现在不存在但将来可能存在的域;)如 yoyo.mama
编辑:
警告!此正则表达式将拒绝以数字或国际域开头的域,因此它比要求的更严格。
well, I used this one
I didn't made this myself, but took from FQDN Regular Expression and edited a bit so it doesn't match just hostname eg. myhost
also take note that it doesn't match reverse domains like 123.213.in-addr.arpa
it will match any TLD, even those which doesn't exist now but might in future ;) like yoyo.mama
EDIT:
WARNING! This regexp will reject domains starting with a digit or international domains thus it's stricter than required.
您可以通过执行以下操作从 IANA 文本文件中获取 TLD 的快速数组:
它只是从 IANA.org 获取文本文件作为数组。然后删除未解析为英文字符 TLD 的注释和国际条目。我相信该文件会定期更新 - 日期位于文件顶部。但我不会向它发送垃圾邮件。
You can get a quick array of TLD's from IANA text file by doing something like this:
It just gets the text file from IANA.org as array. Then removes the comments and international entries that aren't parsed into english character TLDs. I believe this file would be kept up to date on a regular basis - date is at the top of the file. I wouldn't spam it though.
如果有人想知道的话:)
In case anyone whats to know :)