-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTest-IsEmail.ps1
49 lines (39 loc) · 920 Bytes
/
Test-IsEmail.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function Test-IsEmail
{
<#
.SYNOPSIS
Function to check if a string is an RFC email address.
.DESCRIPTION
Function will check if an input string is an RFC complient email address.
.PARAMETER EmailAddress
A string representing the email address to be checked
.EXAMPLE
PS C:\> Test-IsEmail -EmailAddress 'value1'
.OUTPUTS
System.Boolean
.LINK
Restrictions on email addresses
https://tools.ietf.org/html/rfc3696#section-3
#>
[OutputType([bool])]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[Alias('Email', 'Mail', 'Address')]
[string]
$EmailAddress
)
try
{
# Check if address is RFC compliant
[void]([mailaddress]$EmailAddress)
Write-Verbose -Message "Address $EmailAddress is an RFC compliant address"
return $true
}
catch
{
Write-Verbose -Message "Address $EmailAddress is not an RFC compliant address"
return $false
}
}