The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Validate Class - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: Validate Class (/showthread.php?tid=674)



Validate Class - marceloatmartins - 08-18-2017

Hi Everybody,

Did someone make an implementation for validate fields kind "DATE" in Validate Class ?

How can I do it?

Thanks





Validate Class - mudmin - 08-20-2017

No. And we probably need to overhaul that class. I keep running into things it doesn't do. I do my date validation in html.

Code:
<input type="date"




Validate Class - karsen - 08-21-2017

Here is the validation rule that I use. Feel free to adjust the date format to something else.

Code:
case 'valid_date':
Code:
$d = DateTime::createFromFormat('Y-m-d', $value);
Code:
if(($d && $d->format('Y-m-d') == $value)) $valid = true;
Code:
else $valid = false;
Code:
if ($valid != true) {
Code:
$this->addError(["{$display} must be a date with a format of YYYY-MM-DD.", $item]);
Code:
}
Code:
break;



Validate Class - mudmin - 08-22-2017

Awesome! Thanks for this!


Validate Class - karsen - 08-23-2017

I have this and a few others posted in the modifications forum, in one of faguss' threads.

https://userspice.com/forums/topic/validation-class-improvements-2/

They were during your busy months so you may have missed them!


Validate Class - marceloatmartins - 08-25-2017

Wow, really Thanks for help me

I do some tests with "<input type="date", but this doesn't work under Mozilla Firefox and I don't like use javascript a lot for validate fields in form I think that best validations are in back end like Validate Class.

Thank you for all.





Validate Class - mudmin - 08-25-2017

Right. Yeah. JS is not the best way to do it. The newest validate class is in the 4.3 alpha and was just updated a few minutes ago.

https://github.com/mudmin/UserSpice43dev/blob/master/users/classes/Validate.php