简体   繁体   English

PHP检查域名正则表达式(无TLD部分)

[英]PHP check domain name regular expression (withoud tld part)

I am using this code to validate urls: 我正在使用以下代码来验证网址:

if(!filter_var($check_url, FILTER_VALIDATE_URL))
{ echo "URL is not valid"; }
else { echo "OK, valid"; }

Now in most case this is OK, but this will parse: http://www.--tester.com as A VALID DOMAIN ? 现在在大多数情况下可以,但是可以解析: http://www.--tester.com : http://www.--tester.com作为有效域? and dashes are not allowed at the beginning !? 开头不能使用破折号!?

is there a regular expression that will check only NAME (without extension part as it will register only .com domains so that is automatically added and no need to check for it)... so only to check actual name if it is "good to go"... 是否有一个仅用于检查名称的正则表达式(不带扩展名,因为它仅注册.com域,因此它会自动添加,而无需检查)...因此仅检查实际名称,如果“走”...

I guess that input has to be checked only for letters and numbers and dashes (but only if they are NOT AT THE BEGINNING) no dots and other characters. 我猜想只需要检查输入的字母,数字和破折号(但仅当它们不在开始时),点和其他字符即可。

抱歉,有人需要吗?

^([a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9])$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM