Regular Expressions in Visual Basic.net

1

I am doing regular expressions in a registration form using Web forms. I would like to know if it is well done because at the time of registering nothing happens.

This is my regular expression code:

Dim expre_regul As String = "/^[a-zA-Z0-9\._-]+@(hotmail|gmail)[.][a-zA-Z]{2,4}$/"

        Dim r As Regex = New Regex(expre_regul)

        If Not r.IsMatch(txtCorreo.Text) Then
            Return
        End If

This is the full code of my "Register" button

Protected Sub btnRegistrar_Click(sender As Object, e As EventArgs) Handles btnRegistrar.Click

    Try

        Dim clRegistrar As New SIMULADOR_LOG.clsExamenLOG
        Dim User As New SIMULADOR_ENT.clsUsuarioSim
        With User
            .dni_user = txtDNI.Text
            .ape_pat_user = txtApellidoPaterno.Text
            .ape_mat_user = txtApellidoMaterno.Text
            .nombre_user = txtNombres.Text
            .direccion_user = txtDireccion.Text
            .celular_user = txtCelular.Text
            .correo_user = txtCorreo.Text
            .dept_user = cmbDepartamento.Text
            .prov_user = cmbProvincia.Text
            .dist_user = cmbDistrito.Text
            .fech_nacimiento = txtFechaNacimiento.Text
        End With

        Dim expre_regul As String = "/^[a-zA-Z0-9\._-]+@(hotmail|gmail)[.][a-zA-Z]{2,4}$/"

        Dim r As Regex = New Regex(expre_regul)

        If Not r.IsMatch(txtCorreo.Text) Then
            Return
        End If

        Dim mensajeLog As String = clRegistrar.RegistrarUsuario(User)

        Dim Mensaje As String = "<script type=""text/javascript"">" &
                                "Message('El sistema dice: " & mensajeLog & "')</script>"

        ClientScript.RegisterStartupScript(Me.GetType, "msg", Mensaje)

        Response.Redirect("SimuladorExamen.aspx")

    Catch

        'ScriptManager.RegisterStartupScript(Me, GetType(Page), "alerta", "alert('Ingrese un valor válido');", True)

    End Try

End Sub
    
asked by Gian Franco Alexis Poma Vidal 19.12.2018 в 00:08
source

1 answer

0

Use link to test your regular expression.

For example, I used:

  

mail @ mail .com

And the validation tells me that "mail @ mail .com" NO matches the pattern.

But, if I use:

  

mail @ hotmail .com

Validation tells me that "mail @ hotmail .com" does match the pattern.

    
answered by 19.12.2018 в 14:56