Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi all, i wanna ask you about string pattern in regex. I want to validate some strings such as : "IDA0230332", "This is a string", "The number is 8".
I have tried using this code, but it doesn't work. Would u help me please what "string pattern" is the best for that..??

My Code :
C#
private static int IsContaintRegex(string temp)
{
      if (Regex.IsMatch(temp, "^[0-9]+\\s+([a-zA-z]+|[a-zA-z]+\\s+[a-zA-z]+)$", RegexOptions.IgnoreCase).Equals(true))
      {
        return 1;
      }
      else { return 0; }
}
Posted
Updated 25-Oct-10 18:35pm
v2

1 solution

If I understand you right:
C#
string[] strings = { "IDA0230332", "This is a string", "The number is 8", "Hello+sd","55#5"};
          foreach (string str in strings)
          {
              Console.Write(str + "\t\t");
              string reg = @"^(\w|\s)*$";
              if (Regex.IsMatch(str, reg))
              {
                  Console.WriteLine("match");
              }
              else { Console.WriteLine(); }
          }
 
Share this answer
 
Comments
Teamsar Muliadi 26-Oct-10 0:58am    
Hey... it works... :) thanks for giving me solution.. :)

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