Validatore GUID

by davide 7. August 2008 10:35

Lavorando spesso con gli Uniqueidentifier (noti anche come GUID) avevo la necessità di sapere in qualche modo se la stringa passata ad una funzione fosse effettivamente un GUID oppure qualcosa di diverso. Non trovando una funzione predefinita che lo facesse, me ne sono costruito una utilizzando le Regular Expression:

Public Function IsGUID(ByVal guid As String) As Boolean
    Dim rtn As Boolean = False
    If Not String.IsNullOrEmpty(guid) Then
        Dim guidRegEx As Regex = New Regex("^(\{{0,1}" & _
           "([0-9a-fA-F]){8}-([0-9a-fA-F])" & _
           "{4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-" & _
           "([0-9a-fA-F]){12}\}{0,1})$")
        rtn = guidRegEx.IsMatch(guid)
    Else
        rtn = False
    End If

    Return rtn
End Function

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

RegEx | vb.net

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by Esia Software 1.4.0.0

Informazioni sull'autore

Sono un cittadini di Trieste, ho 33 anni e faccio lo sviluppatore nella mia azienda che si chiama Esia Software.

Commenti recenti

Comment RSS

Post recenti

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce.

RecentComments

Comment RSS