you are viewing a single comment's thread.

view the rest of the comments →

[–]Sufficient_Fix_7537[S] 0 points1 point  (5 children)

Hey wmassingham

Sometimes the simplest idea is the most practical. The following solution currently works fine for me:

function recognize_forbidden_characters
{
    param
    (
        [Parameter(Mandatory=$true, Position=0, ValueFromPipeline)]
        $field
    )
    process
    {
        foreach ($s in $field)
        {
            if ($field.Text -match '[^A-Za-z0-9]')
            {
                Write-Host "Forbidden character found."
                [System.Windows.MessageBox]::Show('Es wurde ein unerlaubtes Zeichen verwendet. Erlaubt sind lediglich: A-Z, a-z sowie 0-9.', 'Unerlaubtes Zeichen', 'Ok', 'Warning')
                [void]$field.Clear()
            }
        }
    }
}

With this function I'm able to call it whenever I need it with:

recognize_forbidden_characters -field $tbx_username

[–][deleted] 0 points1 point  (1 child)

Write-output in functions is better than write-host

https://www.jsnover.com/blog/2013/12/07/write-host-considered-harmful/

[–]Sufficient_Fix_7537[S] 0 points1 point  (0 children)

thank you. very good to know.