I am trying to craft a regexp to validate iSCSI qualified names. An example of a qualified name is iqn.2011-08.com.example:storage This is example is minimal, I have seen other examples that are more extended.
So far what I have to validate off of it this:
print "Enter a new target name: ";
my $target_name = <STDIN>;
chomp $target_name;
if ($target_name =~ /^iqn\.\d{4}-\d{2}/xmi) {
print GREEN . "Target name is valid!" . RESET . "\n";
} else {
print RED . "Target name is not valid!" . RESET . "\n";
}
How can I extend that to work with rest up to the : I am not going to parse after the : becuase it is a description tag.
Is there a limit to how big a domain name can be?
According to RFC3270 (and in turn RFC1035),
It’s not clear if the eui names accept lowercase hex digits or not. I figured it was safer to allow them.
If you condense the above, you get
/^(?:iqn\.[0-9]{4}-[0-9]{2}(?:\.[A-Za-z](?:[A-Za-z0-9\-]*[A-Za-z0-9])?)+(?::.*)?|eui\.[0-9A-Fa-f]{16})\z/s.(By the way, your use
/mis wrong, your use of/iis wrong, and\dcan match far more than the allowed[0-9].)