Domitius
Domitius

Reputation: 485

Date input Regex

I have this very nice regex that I got from the net which makes my date inputs dd/MM/yyyy, but now I would like to get it to only be ddMMyyyy, but I can't seem to get the / removed. Any help would be greatly apreciated.

(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\/02\/(19|20)(([02468][048])|([13579][26]))))

Upvotes: 0

Views: 267

Answers (4)

Achim
Achim

Reputation: 15702

You have to remove all the \/.

Upvotes: 1

mroach
mroach

Reputation: 2468

When removing instances of /, make sure you also remove the accompanying \ which is used for escaping.

Upvotes: 1

Yasser
Yasser

Reputation: 1808

Try this:

(((((0[1-9])|(1\d)|(2[0-8]))((0[1-9])|(1[0-2])))|((31((0[13578])|(1[02])))|((29|30)((0[1,3-9])|(1[0-2])))))((20[0-9][0-9])|(19[0-9][0-9])))|((2902(19|20)(([02468][048])|([13579][26]))))

Upvotes: 3

Nicholas Mancuso
Nicholas Mancuso

Reputation: 11877

Is DateTime.TryParse method not appropriate?

Upvotes: 2

Related Questions