|
Posted by Curtis on 02/14/07 03:52
deko wrote:
> Here's a possible way to validate a host's domain name(s):
>
> $invalid = "(~ ` ! @ # $ % ^ & * ( ) _+ = { } [ ] \ | : ; " ' < > , ?
> /)" //pseudo code
> $url_a = parse_url($url);
> $urlHost = $url_a['host'];
> $urlHost_a = explode('.',$urlHost);
> for ($i = count($urlHost_a) - 2; $i > 0 ; $i--) //skips TLD
> {
> if (preg_match($invalid, $urlHost_a[$i]))
> {
> echo 'failed on '.$urlhost_a[$i].'<br>';
> }
> else
> {
> echo 'valid domain name(s)<br>';
> }
> }
>
> Any suggestions on how to construct that $invalid pattern? I'm not sure
> what syntakx to use or what characters need to be escaped.
Again, I would implement it all in one regex, using the /x modifier to
maintain readability. You could use that list of invalid chars in a
negative lookahead - but there are plenty of ways you can do this.
Just not sure how worth it it would be to go all out.
Curtis
Navigation:
[Reply to this message]
|