Private Sub txtSpecialReport_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSpecialReport.TextChanged 'Only allow known characters to be pasted or typed into txtSpecialReport to avoid Conversion Error on characters 'that are okay in access db but not on iSeries when claim is uploaded. Dim intStart As Integer = txtSpecialReport.SelectionStart '^negates the whole thing (we want ones that DON'T match) '\w is for a-zA-Z0-9 '\s is for spaces, tabs, returns '\!\@\#\$\%\^\&\*\(\)\-\=\+\[\]\{\}\\\|\;\:\'\,\<\.\>\/\?\"" are allowed special characters Dim strPattern As String = "[^\w\s\!\@\#\$\%\^\&\*\(\)\-\=\+\[\]\{\}\\\|\;\:\'\,\<\.\>\/\?\""]" Dim myRegex As New System.Text.RegularExpressions.Regex(strPattern) txtSpecialReport.Text = myRegex.Replace(txtSpecialReport.Text, New System.Text.RegularExpressions.MatchEvaluator(AddressOf ReplaceKnownSpecials)) txtSpecialReport.SelectionStart = intStart End Sub Private Function ReplaceKnownSpecials(ByVal match As System.Text.RegularExpressions.Match) As String Select Case Asc(match.Value(0)) Case 63, 146 Return "'" 'Replace an ascii 63 or 146 with ascii 39 Case 133 Return "." 'Replace an ascii 133 elipses with a single period (Not three (...) because then it changes string length) Case 150 Return "-" 'Replace an ascii 150 dash with an ascii 45 dash End Select Return "*" 'Relace any other unknown char with an asterisk End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)