
13/09/2010, 23:41
|
| | Fecha de Ingreso: marzo-2007
Mensajes: 74
Antigüedad: 18 años Puntos: 0 | |
Respuesta: Expresiones Regulares Buenas tardes, necesito validar con la clase regex de .net que en un campo de texto solo puedan haber los siguientes carácteres:
números(0-9)
guiones( - )
comas( , )
no mencionas espacios
asi quedaria
saludos
Public Class Form1
Dim Cont As Integer
Private Function Valida(ByVal s As String) As Boolean
Dim I As Integer
Dim Valor As Boolean
Valor = True
Cont = 1
For I = 1 To Len(s)
Select Case Cont
Case 1
If InStr("0123456789", Mid(s, I, 1)) > 0 Then
Cont = 2
Else
Valor = False
Exit For
End If
Case 2
If InStr("-", Mid(s, I, 1)) > 0 Then
Cont = 3
Else
If InStr("0123456789", Mid(s, I, 1)) = 0 Then
Valor = False
Exit For
End If
End If
Case 3
If InStr("0123456789", Mid(s, I, 1)) > 0 Then
Cont = 4
Else
Valor = False
Exit For
End If
Case 4
If InStr(",", Mid(s, I, 1)) > 0 Then
Cont = 1
Else
If InStr("0123456789", Mid(s, I, 1)) = 0 Then
Valor = False
Exit For
End If
End If
End Select
Next I
If Valor = False Then
Valida = Valor
Else
If Cont = 3 Or Cont = 1 Then
Valida = False
Else
Valida = True
End If
End If
End Function
Private Sub Button1_Click(ByVal sender As system.Object, ByVal e As system.EventArgs) Handles Button1.Click
If Valida(TxtDato.Text) Then
MsgBox("Correcto")
Else
MsgBox("Incorrecto [" & TxtDato.Text & "]")
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class |