begin process at 2012 05 27 06:09:15
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

ASP.Net

 > CLASSE DE VALIDATION

CLASSE DE VALIDATION


 Information sur la source

Note :
Aucune note
Catégorie :ASP.Net Source .NET ( DotNet ) Classé sous :validation, valide, email, regexp Niveau :Débutant Date de création :02/04/2004 Date de mise à jour :02/04/2004 21:34:19 Vu / téléchargé :10 611 / 175

Auteur : jesusonline

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note


 Description

Cette classe permet de Valider certaines données pour l'instant il n'y a pas grand chose, mais j'en rajouterais quand j'en aurais besoin, j'ai mis l'email qui peut etre interessantet les test sur les nombres

Je me suis fortement inspiré de la source de Fabrice69 : http://www.aspfr.com/code.aspx?ID=21154

Dans le zip vous avez une assembly contenant d'autre truc sur lequel je travail, pour avoir la dernier version de celle ci :
http://jesusonline.free.fr/Cyril/
Y'a la description de la classe ici : http://jesusonline.free.fr/Cyril/Commentaire%2002. Avril.2004/Solution_Cyril.HTM


Fonctionnement

Dim Valid As New Cyril.Utility.Validation.StringValidation
if Valid.isEmail("MonEmail@codes-sources.com") then
          'Mail Valide'
end if





Source

  • ''' -----------------------------------------------------------------------------
  • ''' Project : Cyril
  • ''' Class : Utility.Validation
  • '''
  • ''' -----------------------------------------------------------------------------
  • ''' <summary>
  • ''' Desolé classe non commenté :(
  • '''
  • ''' Pour la realisation de celle ci je me suis fortement inspiré d'une source
  • ''' de Fabrice69 : http://www.aspfr.com/code.aspx?ID=21154
  • ''' </summary>
  • ''' <remarks>
  • ''' </remarks>
  • ''' <history>
  • ''' [DURAND Cyril] 02/04/2004 Created
  • ''' </history>
  • ''' -----------------------------------------------------------------------------
  • Public Class Validation
  • Private _RegExp As String
  • Public Property RegExp() As String
  • Get
  • Return _RegExp
  • End Get
  • Set(ByVal Value As String)
  • _RegExp = Value
  • End Set
  • End Property
  • #Region "Constructeurs"
  • Public Sub New()
  • End Sub
  • Public Sub New(ByVal PersonalRegexp As String)
  • _RegExp = PersonalRegexp
  • End Sub
  • #End Region
  • Public Overridable Function isInteger(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,10}$")
  • If objIntPattern.IsMatch(_Value) = True Then
  • If CType(_Value, Decimal) <= 2 ^ 31 - 1 And CType(_Value, Decimal) >= 2 ^ 31 Then
  • Return objIntPattern.IsMatch(_Value)
  • End If
  • Else
  • Return False
  • End If
  • End Function
  • Default Public Overloads ReadOnly Property isPersonnalExpression(ByVal _Value As String, ByVal PersonalRegexp As String) As Boolean
  • Get
  • If PersonalRegexp = Nothing Then
  • Throw New Exception("Absence de l'expression de validation")
  • Exit Property
  • End If
  • Try
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex(RegExp)
  • Return objIntPattern.IsMatch(_Value)
  • Catch ex As Exception
  • Throw New Exception("Expression de validation non valide : " & PersonalRegexp & ". L'erreur est : " & ex.Message, ex)
  • Exit Property
  • End Try
  • End Get
  • End Property
  • Default Public Overloads ReadOnly Property isPersonnalExpression(ByVal _Value As String) As Boolean
  • Get
  • If _RegExp = Nothing Then
  • Throw New Exception("Absence de l'expression de validation")
  • Exit Property
  • End If
  • Try
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex(_RegExp)
  • Return objIntPattern.IsMatch(_Value)
  • Catch ex As Exception
  • Throw New Exception("Expression de validation non valide : " & _RegExp & ". L'erreur est : " & ex.Message, ex)
  • Exit Property
  • End Try
  • End Get
  • End Property
  • Public Class StringValidation
  • Inherits Validation
  • Public Function isEmail(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$")
  • Return objIntPattern.IsMatch(_Value)
  • End Function
  • End Class
  • Public Class NumericValidation
  • Inherits Validation
  • Public Function isBin(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[0-1]+[0-1]*$")
  • Return objIntPattern.IsMatch(_Value)
  • End Function
  • Public Function IsDec(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?\d{1,29}$")
  • Return objIntPattern.IsMatch(_Value)
  • End Function
  • Public Function isInt32(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,10}$")
  • If objIntPattern.IsMatch(_Value) = True Then
  • If CType(_Value, Decimal) <= 2 ^ 31 - 1 And CType(_Value, Decimal) >= 2 ^ 31 Then
  • Return objIntPattern.IsMatch(_Value)
  • End If
  • Else
  • Return False
  • End If
  • End Function
  • Public Function isInt16(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,5}$")
  • If objIntPattern.IsMatch(_Value) = True Then
  • If CType(_Value, Decimal) <= 2 ^ 15 - 1 And CType(_Value, Decimal) >= 2 ^ 15 Then
  • Return objIntPattern.IsMatch(_Value)
  • End If
  • Else
  • Return False
  • End If
  • End Function
  • Public Function isSbyte(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,3}$")
  • If objIntPattern.IsMatch(_Value) = True Then
  • If CType(_Value, Decimal) <= 127 And CType(_Value, Decimal) >= -128 Then
  • Return objIntPattern.IsMatch(_Value)
  • End If
  • Else
  • Return False
  • End If
  • End Function
  • Public Function isByte(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,3}$")
  • If objIntPattern.IsMatch(_Value) = True Then
  • If CType(_Value, Decimal) <= 255 Then
  • Return objIntPattern.IsMatch(_Value)
  • End If
  • Else
  • Return False
  • End If
  • End Function
  • Public Function isHex(ByVal _Value As String) As Boolean
  • Dim objIntPattern As New System.Text.RegularExpressions.Regex("^#?([a-f]|[A-F]|[0-9])*$")
  • Return objIntPattern.IsMatch(_Value)
  • End Function
  • Public Class NumericConversion
  • Inherits NumericValidation
  • Public Function toInt32(ByVal _Value As String) As Integer
  • If Me.isInt32(_Value) = True Then
  • Return CType(_Value, Integer)
  • Else
  • Throw New Exception("Convertion impossible")
  • End If
  • End Function
  • Public Function toInt16(ByVal _Value As String) As Int16
  • If Me.isInt16(_Value) = True Then
  • Return CType(_Value, Integer)
  • Else
  • Throw New Exception("Convertion impossible")
  • End If
  • End Function
  • Public Function toByte(ByVal _Value As String) As Byte
  • If Me.isByte(_Value) = True Then
  • Return CType(_Value, Byte)
  • Else
  • Throw New Exception("Convertion impossible")
  • End If
  • End Function
  • Public Function toHexString(ByVal _Value As String) As String
  • If Me.isHex(_Value) = True Then
  • Return _Value
  • Else
  • Throw New Exception("Convertion impossible")
  • End If
  • End Function
  • Public Function toDec(ByVal _Value As String) As Decimal
  • If Me.IsDec(_Value) = True Then
  • Return CType(_Value, Decimal)
  • Else
  • Throw New Exception("Convertion impossible")
  • End If
  • End Function
  • End Class
  • End Class
  • End Class
    ''' -----------------------------------------------------------------------------
    ''' Project	 : Cyril
    ''' Class	 : Utility.Validation
    ''' 
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Desolé classe non commenté :(
    ''' 
    ''' Pour la realisation de celle ci je me suis fortement inspiré d'une source 
    ''' de Fabrice69 : http://www.aspfr.com/code.aspx?ID=21154
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[DURAND Cyril]	02/04/2004	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Class Validation

        Private _RegExp As String
        Public Property RegExp() As String
            Get
                Return _RegExp
            End Get
            Set(ByVal Value As String)
                _RegExp = Value
            End Set
        End Property

#Region "Constructeurs"

        Public Sub New()
        End Sub
        Public Sub New(ByVal PersonalRegexp As String)
            _RegExp = PersonalRegexp
        End Sub

#End Region


        Public Overridable Function isInteger(ByVal _Value As String) As Boolean
            Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,10}$")
            If objIntPattern.IsMatch(_Value) = True Then
                If CType(_Value, Decimal) <= 2 ^ 31 - 1 And CType(_Value, Decimal) >= 2 ^ 31 Then
                    Return objIntPattern.IsMatch(_Value)
                End If
            Else
                Return False
            End If

        End Function

        Default Public Overloads ReadOnly Property isPersonnalExpression(ByVal _Value As String, ByVal PersonalRegexp As String) As Boolean
            Get
                If PersonalRegexp = Nothing Then
                    Throw New Exception("Absence de l'expression de validation")
                    Exit Property
                End If

                Try
                    Dim objIntPattern As New System.Text.RegularExpressions.Regex(RegExp)
                    Return objIntPattern.IsMatch(_Value)
                Catch ex As Exception
                    Throw New Exception("Expression de validation non valide : " & PersonalRegexp & ". L'erreur est : " & ex.Message, ex)
                    Exit Property
                End Try
            End Get
        End Property
        Default Public Overloads ReadOnly Property isPersonnalExpression(ByVal _Value As String) As Boolean
            Get
                If _RegExp = Nothing Then
                    Throw New Exception("Absence de l'expression de validation")
                    Exit Property
                End If

                Try
                    Dim objIntPattern As New System.Text.RegularExpressions.Regex(_RegExp)
                    Return objIntPattern.IsMatch(_Value)
                Catch ex As Exception
                    Throw New Exception("Expression de validation non valide : " & _RegExp & ". L'erreur est : " & ex.Message, ex)
                    Exit Property
                End Try
            End Get
        End Property

        Public Class StringValidation
            Inherits Validation

            Public Function isEmail(ByVal _Value As String) As Boolean
                Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$")
                Return objIntPattern.IsMatch(_Value)
            End Function


        End Class

        Public Class NumericValidation
            Inherits Validation

            Public Function isBin(ByVal _Value As String) As Boolean
                Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[0-1]+[0-1]*$")
                Return objIntPattern.IsMatch(_Value)
            End Function

            Public Function IsDec(ByVal _Value As String) As Boolean
                Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?\d{1,29}$")
                Return objIntPattern.IsMatch(_Value)
            End Function

            Public Function isInt32(ByVal _Value As String) As Boolean
                Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,10}$")
                If objIntPattern.IsMatch(_Value) = True Then
                    If CType(_Value, Decimal) <= 2 ^ 31 - 1 And CType(_Value, Decimal) >= 2 ^ 31 Then
                        Return objIntPattern.IsMatch(_Value)
                    End If
                Else
                    Return False
                End If

            End Function

            Public Function isInt16(ByVal _Value As String) As Boolean
                Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,5}$")
                If objIntPattern.IsMatch(_Value) = True Then
                    If CType(_Value, Decimal) <= 2 ^ 15 - 1 And CType(_Value, Decimal) >= 2 ^ 15 Then
                        Return objIntPattern.IsMatch(_Value)
                    End If
                Else
                    Return False
                End If

            End Function

            Public Function isSbyte(ByVal _Value As String) As Boolean
                Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,3}$")
                If objIntPattern.IsMatch(_Value) = True Then
                    If CType(_Value, Decimal) <= 127 And CType(_Value, Decimal) >= -128 Then
                        Return objIntPattern.IsMatch(_Value)
                    End If
                Else
                    Return False
                End If

            End Function

            Public Function isByte(ByVal _Value As String) As Boolean
                Dim objIntPattern As New System.Text.RegularExpressions.Regex("^[-]?0*\d{1,3}$")
                If objIntPattern.IsMatch(_Value) = True Then
                    If CType(_Value, Decimal) <= 255 Then
                        Return objIntPattern.IsMatch(_Value)
                    End If
                Else
                    Return False
                End If

            End Function

            Public Function isHex(ByVal _Value As String) As Boolean
                Dim objIntPattern As New System.Text.RegularExpressions.Regex("^#?([a-f]|[A-F]|[0-9])*$")
                Return objIntPattern.IsMatch(_Value)
            End Function

            Public Class NumericConversion
                Inherits NumericValidation

                Public Function toInt32(ByVal _Value As String) As Integer
                    If Me.isInt32(_Value) = True Then
                        Return CType(_Value, Integer)
                    Else
                        Throw New Exception("Convertion impossible")
                    End If
                End Function
                Public Function toInt16(ByVal _Value As String) As Int16
                    If Me.isInt16(_Value) = True Then
                        Return CType(_Value, Integer)
                    Else
                        Throw New Exception("Convertion impossible")
                    End If
                End Function
                Public Function toByte(ByVal _Value As String) As Byte
                    If Me.isByte(_Value) = True Then
                        Return CType(_Value, Byte)
                    Else
                        Throw New Exception("Convertion impossible")
                    End If
                End Function
                Public Function toHexString(ByVal _Value As String) As String
                    If Me.isHex(_Value) = True Then
                        Return _Value
                    Else
                        Throw New Exception("Convertion impossible")
                    End If
                End Function
                Public Function toDec(ByVal _Value As String) As Decimal
                    If Me.IsDec(_Value) = True Then
                        Return CType(_Value, Decimal)
                    Else
                        Throw New Exception("Convertion impossible")
                    End If
                End Function

            End Class

        End Class


    End Class

 Conclusion

Cette classe est la pour évoluer, je serais ravis d'ajouter vos propre validation donc n'hésiter surtout pas à me faire part de vos création ...

dites moi ce que vous en pensez via les commentaires ...

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source .NET (Dotnet) UTILISATION DE LA MÉTHODE SORT ET SORTDIRECTION AVEC UN GRID...
Source .NET (Dotnet) RESPONSE.FILTER : MANIPULATION DU STREAM DE SORTIE ASP.NET
Source avec Zip Source .NET (Dotnet) OPTIMISATION DE LA SERIALISATION JSON POUR LES LIST<T>
Source avec Zip Source .NET (Dotnet) CRAWLABLELINKBUTTON : UPDATEPANEL ET RÉFÉRENCEMENT
Source .NET (Dotnet) POSTBACKCONTROL - COMMUNICATION CLIENT/SERVEUR AVEC LES UPDA...

 Sources de la même categorie

Source avec Zip Source .NET (Dotnet) GUESTBOOK AVEC GRIDVIEW par DanMor498
Source avec Zip CHECKED DROPDOWNLIST par fredzool
Source avec Zip Source avec une capture Source .NET (Dotnet) GRIDVIEW WITH TREEVIEW AND CALLBACK par fredzool
Source avec Zip APPELLER UN WEBSERVICE DEPUIS JAVASCRIPT par fredzool
Source avec Zip Source .NET (Dotnet) MONEY TEXTBOX WITH EMBEDED JAVASCRIPT par fredzool

 Sources en rapport avec celle ci

Source avec Zip Source .NET (Dotnet) HIDDENEMAIL : MASQUER VOS EMAILS AUX ROBOTS par sebmafate
Source .NET (Dotnet) C# - FONCTION TRÈS SIMPLE POUR ENVOYER UN MAIL VIA SMTP par fabrice69
VALIDITER EMAIL TRES SIMPLE !!! par Jackboy
VALIDATION DU FORMAT D'UNE URL (REGEXP) par Jos
VALIDATION D'UN EMAIL, EN QUELQUES LIGNES... par Jos

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

[ASP.NET]validation d'un champ email [ par shadow1779 ] Bonjour, j'essaye de vérifier un formulaire avant de faire le postback ca marche pour tous les champs sauf l'adresse email, quelqu'un saurrait t'il po Prob d'envoi d'email avec CDO [ par allserv ] Bonjour tout le monde, Voici mon problème, j'ai une erreur lors de l'envoi d'un email avec CDO, (connexion perdue avec le serveur) la taille du corp Validation d'une date [ par alexandre_69 ] Salut !J'ai un ptit souci avec la validation d'une date en asp.net (c#) ! Jai essayé avec un compare validator sur mon champ de texte ! Je souhaiterai Problème envois mail avec iiS 7.0 [ par gatita_dev ] Bonjour, j'essaye d'envoyer un email en utilisant asp.net via mon serveur local IIS, j'ai configuré le SMTP comme suitNom du serveur : LocalHostPort d validation d'une adresse IP avec masque asp.net [ par meryad ] Bonjour,Je voudrais vérifier dans un champ d'un formulaire si une adresse IP avec masque est valide ou pas.J'ai trouvé le code de validation d'une adr envoyer un email en asp/c# [ par bain ] Bonjour j'ai un problème au niveau de mon envoi d'email.Voici la partie de mon fichier .aspx.cs qui concerne ce point:using System.Web.Mail;        Ma RegularExpressionValidator ne vérifie pas toujours le champ à valider [ par Alexandre Marlot ] Bonjour à tous.J'ai contaté que lorsque j'utilise un RegularExpressionValidator sur un champ Email et que le navigateur propose une liste de choix pou enableviewstate erreur [ par sasmami ] bonjour,je developpe en asp.net avec vs2005. et dans une aspx j'ai un gridview avec des boutons. dés que je clique sur un de ces boutons j'obtien l'er email [ par le_roi_hidri ] je veux faire une tache planifier pour envoyer des fichier vers une adresse email .sans que j'interviens . a tenir compte que mon ordinateur et connec Validation Control [ par blueangel ] Salut tout le monde,voici mon code&lt;inputid<font color="#0000ff" size


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,934 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales