Private Sub TextBox9_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox9.KeyPress If InStr("9503621-RJ", e.KeyChar) = 0 And e.KeyChar <> vbBack Then e.Handled = True End Sub
9503622111111111111111111111111111111111111111111111111111111111111111111111111111111111111-RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRsans problème.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSelect Case toto Case "A", "B" 'ici le code pour A et B Case Else 'ici le code pour le reste End Select
Imports System.Text.RegularExpressions Module Module1 Sub Main() Dim sourcestring as String = "replace with your source string" Dim re As Regex = New Regex("^[9503621\-RJ]*$",RegexOptions.Multiline) Dim mc as MatchCollection = re.Matches(sourcestring) Dim mIdx as Integer = 0 For each m as Match in mc For groupIdx As Integer = 0 To m.Groups.Count - 1 Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value) Next mIdx=mIdx+1 Next End Sub End Module
$matches Array:Pour la chaine de caractères :
(
[0] => Array
(
[0] => 99550033662211--RRJJ
)
)
99550033662211--RRJJ
NO MATCHES.
OPr77861122_-XDJ
Public Class Form1
Private Ok As Boolean
Private Sub Accueil_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Ok = "9503621-RJ".Contains("5") : MessageBox.Show(Ok.ToString)
Ok = "9503621-RJ".Contains("4") : MessageBox.Show(Ok.ToString)
End Sub
End Class
Likeou
caseou
regex!
Private Sub TextBox9_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox9.KeyPress If InStr("9503621-RJ", e.KeyChar) = 0 And e.KeyChar <> vbBack Then e.Handled = True End Sub
OS : Windows 7 Pro 64 Bit Plateforme : Visual Studio 2010
Imports System.Text.RegularExpressions Public Class Form1 Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged Dim sourcestring As String = Me.TextBox1.Text Dim re As Regex = New Regex("^[9503621\-RJ]*$") Dim mc As Match = re.Match(sourcestring) If mc.Success Then 'saisie OK Console.WriteLine(mc.Value & " =>> OK") Else 'Saisie KO Console.WriteLine("Saisie Fausse") End If End Sub End Class