On 2005-04-20, Dean Slindee <sl*****@charter.net> wrote:
Anyone have a link to a list of Regex.IsMatch expressions for commonly used
edits, like phone number, date, ssn, etc. An example below was copied from
a book source, but is returning false on "01/01/2005" in strDate. (Just
starting into regular expressions).
Return (Regex.IsMatch(strDate, "^(0[1-9]|1[0-2])[./-]" + _
' "(0[1-9]|1[0-9]|2[0-9]|3[0-1])" + _
' "[./-](\\d{2}|\\d{4})$"))
As Cor mentioned, Expresso (
http://www.ultrapico.com/Expresso.htm) is a
good source of regexes as well as a good app to test them in.
On the above examples, though, a common problem in copying from books
into VB.Net is that a lot of languages force one to escape the backslash
character, while VB.Net does not. In languages like C, you'd type "\\"
when you really want "\".
That's the problem above. Replace "\\d" with "\d" and the regex should
work fine.