我的问题是我不想让用户输入任何错误的内容,所以我试图删除它,我的问题是我制作了一个正则表达式,它可以除去除单词以外的所有内容,并且也会将、- 这些标志删除,但我需要这些标志来让用户感到开心:D
简而言之,此脚本使用正则表达式从输入字段中删除坏字符。
输入字段:
简而言之,此脚本使用正则表达式从输入字段中删除坏字符。
输入字段:
$CustomerInbox = New-Object System.Windows.Forms.TextBox #initialization -> initializes the input box
$CustomerInbox.Location = New-Object System.Drawing.Size(10,120) #Location -> where the label is located in the window
$CustomerInbox.Size = New-Object System.Drawing.Size(260,20) #Size -> defines the size of the inputbox
$CustomerInbox.MaxLength = 30 #sets max. length of the input box to 30
$CustomerInbox.add_TextChanged($CustomerInbox_OnTextEnter)
$objForm.Controls.Add($CustomerInbox) #adding -> adds the input box to the window
功能:
$ResearchGroupInbox_OnTextEnter = {
if ($ResearchGroupInbox.Text -notmatch '^\w{1,6}$') { #regex (Regular Expression) to check if it does match numbers, words or non of them!
$ResearchGroupInbox.Text = $ResearchGroupInbox.Text -replace '\W' #replaces all non words!
}
我不想出现的坏字符:
~ " # % & * : < > ? / \ { | } #those are the 'bad characters'
\W
?请使用[~"#%&*:<>?/\\{|}]
。但是,您还应该考虑像con
、lpt1
等文件名。 - Wiktor Stribiżew