以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请教字符串不能包含特定字符的判断怎么写  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=124753)

--  作者:rogen
--  发布时间:2018/9/13 9:23:00
--  请教字符串不能包含特定字符的判断怎么写
请教,文本框里不能输入 \\ / | : * ? " < >这些文件夹不能使用的字符的判断该怎么写正则表达式?
--  作者:有点甜
--  发布时间:2018/9/13 9:27:00
--  

textchanged事件,写代码

 

Dim txt As String = e.Sender.Text
If txt > "" Then
    Dim pattern As String = "[*? |""/\\\\|:]"
    Dim str As String = System.Text.RegularExpressions.Regex.Replace(txt , pattern ,"")
    e.Sender.Text = str
    e.sender.SelectionStart = str.Length
End If


--  作者:rogen
--  发布时间:2018/9/13 9:34:00
--  
谢谢,我是希望点击按钮后,能提示不能含有这些字符,不用自动去掉它们。
--  作者:有点甜
--  发布时间:2018/9/13 9:37:00
--  

Dim pattern As String =  "[*? |""/\\\\|:]+"
Dim txt As String = "abc\\"

Dim rgx = new System.Text.RegularExpressions.Regex(pattern)
If rgx.isMatch(txt) Then
    msgbox("错误")
End If


--  作者:rogen
--  发布时间:2018/9/13 9:43:00
--  
以下是引用有点甜在2018/9/13 9:37:00的发言:

Dim pattern As String =  "[*? |""/\\\\|:]+"
Dim txt As String = "abc\\"

Dim rgx = new System.Text.RegularExpressions.Regex(pattern)
If rgx.isMatch(txt) Then
    msgbox("错误")
End If

好用,谢谢!