Date validation? |
[eluser]Mart[/eluser]
Hi I was expecting to be able to use the CI Validation class to to validate dates on my forms. The user guide doesn't show any examples. Does the validation class class support date checking? How would I go about it otherwise? (Callbacks? I could use one of those I guess) Cheers
[eluser]Kemik[/eluser]
[quote author="alpar" date="1189898488"]why regex? How about php's checkdate? I think it provides stronger validation than what you can achieve with a regex[/quote] I only use regex because my date is typed in to a text field so it's not in three variables.
[eluser]Michael Wales[/eluser]
Personally, I like to incorporate a JS calendar for all of my date fields - Yahoo's UI is a great option.
[eluser]Mart[/eluser]
I agree a regex would suit me best. Here's my callback Code: function date_check($date) I know the regex string is valid but I'm getting: Code: Message: preg_match() [function.preg-match]: Unknown modifier '[' Do I need to reformat my regex to be used in PHP? Cheers
[eluser]feri_soft[/eluser]
Why are you quoting the variable? I doubt thats the problem but however why is that: Code: if(preg_match("$ddmmyyy", $date)) { and not Code: if(preg_match($ddmmyyy, $date)) {
[eluser]Mart[/eluser]
No reason other than me trying to work out why PHP doesn't like the regex (even though I know it works in QuickREx (Eclipse plugin for building & testing regex). I've tried both, btw...
[eluser]Mart[/eluser]
Ha! - nailed it! Code: function date_check($date) { It seems I needed to add "/" and "$/" to the front and back of the expression and then escape the x2 "/." with "\/." :cheese: Told you I needed those double quotes ;-) (well not really I suppose) Thanks for the input. And here's a working solution for others hopefully...
[eluser]xcristi[/eluser]
Here is my validate function from libraries/Validation.php Code: function validdate($str) The main improvement here is checkdate function. |
Welcome Guest, Not a member yet? Register Sign In |