Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using Asp.net MVC4 and WCF. can anybody pls tell me how to give Regular expression for GUID.

Thanking you.
Posted

An empty Guid is always the same value: 00000000-0000-0000-0000-000000000000
So the Regex would be trivial:
00000000-0000-0000-0000-000000000000


Why do I get the feeling this is not the question you meant to ask?
 
Share this answer
 
try this:

C#
public static bool IsGUID(string expression)
{
    if (expression != null)
    {
        Regex guidRegEx = 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})$");

        return guidRegEx.IsMatch(expression);
    }
    return false;
}
 
Share this answer
 
Comments
Prasad_Kulkarni 13-Jul-12 0:07am    
My 5!
Manas Bhardwaj 13-Jul-12 3:45am    
thx Prasad. btw I have a (free) full one month subscription for PluralSight, if you are interested let me know :)
Prasad_Kulkarni 13-Jul-12 5:45am    
Of course I am, Glad to hear that. What do I need to do, means how I can get access of it.
Manas Bhardwaj 13-Jul-12 5:50am    
Will pass on the details this weekend.
Prasad_Kulkarni 13-Jul-12 5:52am    
That's so nice. Excited!!!!! will learn sooo many new things.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900