• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1150
  • Last Modified:

why does the following hostname still not validate?

hi, i am trying to add %.static.westdc.net to the blacklist but the following javascript still detects it as invalid - yet it should be allowed...
the value eml contains either an email, ip or host name and is tested against the following perl compatible regular expressions (pcre's).
var ml = /^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i;
var ip = /^[\d\%]{1,3}\.[\d\%]{1,3}\.[\d\%]{1,3}\.[\d\%]{1,3}$/i;
var hn = /^(?![0-9]+$)(?!-)[a-zA-Z0-9%-]{1,63}(?!-)$/i;
if (!ml.test(eml) && !ip.test(eml) && !hn.test(eml)) {
	salert("Invalid E-Mail, IP or DNS Address detected!\n\nMust either be a valid E-Mail, or a valid IP or DNS (host name) address - allowing for % subdomain wildcards.");
	document.getElementById("ajaxbg").style.visibility = "hidden";
	document.form_blacklist.text_listedaddress.focus();
	return false;
}

Open in new window

ip addresses validate, as well as email addresses... just hostnames? this is strange, but i must admit - i am no guru with regular expressions!

i thought the previous topic was answered - but apparently not... -_-
0
intellisource
Asked:
intellisource
1 Solution
 
HonorGodCommented:
ml.test() fails because the ml RegExp requires a @ sign.
0
 
käµfm³d 👽Commented:
The hostname regex does not (currently) permit dots. Given your example string, I would expect that it should. Perhaps try:

var hn = /^(?![0-9]+$)(?![-.])[a-zA-Z0-9%.-]{1,63}(?![.-])$/i;

Open in new window

0
 
intellisourceAuthor Commented:
thanks for noting that! i believe i missed that, these host names being network names and not internet hostnames... ^^ thanks! :D

and it was supposed to fail on the email check because it was not an email address but a host name / dns address! ;)

it checks if all of the conditions fail before kicking out a warning and returning false. so it could either be an email, an ip or a dns address :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now