Textbox and RegEx

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Textbox and RegEx

Post by MarvelManiac »

We have servers and PCs in our environment
trying to force the users to make sure it's typed in correct in a textbox for validation
so example PC123 or SRV123
$textbox1_TextChanged={
if ($textbox1.Text.trim() -match '[Pp]{1}[Cc]{1}\d{3}$|[Ss]{1}[Rr]{1}[Vv]{1}\d{3}$')
{script}
}
else{$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Please type in correct Name", 0, "Notification")}

Not matter what I type, I get the popup
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Textbox and RegEx

Post by jvierra »

How are you going to spell check? Why not use an autocompletion list restricted to only members of the list?
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Re: Textbox and RegEx

Post by MarvelManiac »

Not really spell check.. I just don't want them to be able to input anything but PC123 or SRV123. This is what I'm hoping my regex does, but that doesn't seem to be working as I expected.

The technicians will either type the PC name in 1 letter at a time or copy and paste the PC name
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Textbox and RegEx

Post by jvierra »

Add those two items to the list.

For two items I would use a pair of checkboxes.
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Re: Textbox and RegEx

Post by MarvelManiac »

This is a gui to install an application out of a few thousand

so tech gets a call to install software, they can copy and paste from the ticket, or type in the characters individually

Copy and paste seems to be working fine.
This topic is 5 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked