You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Test-ValidDomainName uses a regular expression match to test whether DomainName is a valid domain name. The match pattern is the generally-accepted regular expression from http://stackoverflow.com/a/20204811/1404637
9
+
10
+
.OUTPUTS
11
+
Returns true when DomainName is a valid domain name. Returns false otherwise.
12
+
13
+
.EXAMPLE
14
+
'as-d.jkl' | Test-ValidDomainName
15
+
# true
16
+
17
+
as-d.jkl is a valid domain name.
18
+
19
+
.EXAMPLE
20
+
'-asd.jkl' | Test-ValidDomainName
21
+
# false
22
+
23
+
Labels cannot start or end with hyphen.
24
+
25
+
.LINK
26
+
http://stackoverflow.com/a/20204811/1404637
27
+
#>
28
+
[CmdletBinding()]
29
+
param
30
+
(
31
+
# The domain name to test for validity.
32
+
[Parameter(Mandatory=$true,
33
+
Position=1,
34
+
ValueFromPipeline=$true)]
35
+
[AllowEmptyString()]
36
+
[string]
37
+
$DomainName
38
+
)
39
+
process
40
+
{
41
+
# http://stackoverflow.com/a/20204811/1404637
42
+
43
+
if ( $DomainName-notmatch'(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)' )
44
+
{
45
+
&(Publish-Failure"$DomainName is not a valid domain name.",'DomainName' ([System.ArgumentException]))
0 commit comments