Regular expressions.....

  • Thread starter Thread starter Peter Smith
  • Start date Start date
P

Peter Smith

I am writing some validations code to make sure that date string data has
only two "/" characters in a string. Order of appearance of "/" is
irrespective.

How to write a regular expressions code to validate that a given string has
only two "/" in a given string. .Net 1.1.

Thanks,

Smith
 
Hi Peter ! :O)

Do you really need a regular expression ?
There many ways to perform this test... here's three of them including a
Regex solution.. :
'***
Dim s As String = "my / test / string"
Console.WriteLine(s.Split("/").Length - 1 = 2)
Console.WriteLine(s.Length - s.Replace("/", "").Length = 2)
Console.WriteLine(Regex.IsMatch(s, "^([^/]*)/{1}([^/]*)/{1}([^/]*)$"))
'***
 
I am writing some validations code to make sure that date string data has
only two "/" characters in a string. Order of appearance of "/" is
irrespective.

How to write a regular expressions code to validate that a given string has
only two "/" in a given string. .Net 1.1.

Thanks,

Smith

You could just use DateTime.ParseExact with your needed format.
 
Back
Top