开发者

iRegex for date in user entered textfield

开发者 https://www.devze.com 2022-12-22 19:21 出处:网络
I have an input box and the user can write his DOB(mm/dd/yyyy) into the box. Before I save the data I like to test for valid input. I am u开发者_StackOverflow中文版sing Regexlite.h and Regexlite.m.I h

I have an input box and the user can write his DOB(mm/dd/yyyy) into the box. Before I save the data I like to test for valid input. I am u开发者_StackOverflow中文版sing Regexlite.h and Regexlite.m.I have the regular expression too. I want to compare the regex to the user entered value in text box.But am not knowing how to do it.

Any idea how to test for a valid date? (in .NET I use a simple regex but for the iPhone sdk I am a bit helpless) - but somebody must have been done this before.


Here is a regex you can use to parse it if your looking for something else just leave me a comment

^\d{2}/\d{2}/\d{4}$


I think that you should do more validation than that---you don't want anything happening on 30 February nor allow a birth-year of 1001 and 3001 (time-travellers and Methusaleh's Children can go hang).

Perhaps someone cleverer than I could do this all with regular expressions, but I'd suggest just looking at the string and using some logic.


Why are you not using UIDatePicker to prevent user to enter your own not valid date.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号