• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Date Validation

Date Validation 13 years 6 months ago #11859

  • Someone
  • Someone's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 1
Cos there is no textfield date validation, I wrote my own:

components/com_rsform/validation.php
function mydate($param, $extra = 'dd.mm.yyyy'){
 
            if(strlen($param) >= 6 && strlen($extra) == 10){
 
                // find separator. Remove all other characters from $extra
                $separator_only = str_replace(array('m','d','y'),'', $extra);
                $separator = $separator_only[0]; // separator is first character
 
                if($separator && strlen($separator_only) == 2){
                    // make regex
   		    $regexp = str_replace($separator, "\\" . $separator, $extra);
                    $regexp = str_replace('mm', '(0?[1-9]|1[0-2])', $regexp);
                    $regexp = str_replace('dd', '(0?[1-9]|[1-2][0-9]|3[0-1])', $regexp);
                    $regexp = str_replace('yyyy', '(19|20)?[0-9][0-9]', $regexp);
 
                    if($regexp != $param && preg_match('/'.$regexp.'\\z/', $param)){
 
                        // check date
                        $arr=explode($separator,$param);
                        $day=$arr[0];
                        $month=$arr[1];
                        $year=$arr[2];
                        if(@checkdate($month, $day, $year))
                            return true;
                    }
                }
            }
            return false;
        }
administrator/components/com_rsform/assets/js/scripts.js:504
change
if(elem.value == 'custom' || elem.value == 'numeric' || elem.value == 'alphanumeric' || elem.value == 'alpha')
to
if(elem.value == 'custom' || elem.value == 'numeric' || elem.value == 'alphanumeric' || elem.value == 'alpha' || elem.value == 'mydate')

Would be nice to have it already included in future releases.
The Code is based on a function found on php.net

cheers
Someone

[EDIT]
The forum soft messes with the code
There are TWO backslashes in that line....

$regexp = str_replace($separator, "\\" . $separator, $extra);

Don't forget to add the date format in Validation Extra e.g dd/mm/yyyy or dd.mm.yyyy
Last Edit: 13 years 5 months ago by Someone.
The administrator has disabled public write access.
The following user(s) said Thank You: webcat-solutions

Re:Date Validation 13 years 6 months ago #11860

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
Nice to see users that actually contribute to the forum.

Thank you!
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Re:Date Validation 13 years 6 months ago #11918

You also need a backslashe just before the z/ here :
if($regexp != $param && preg_match('/'.$regexp.'\\z/', $param))

For the source code see here : fr2.php.net/manual/en/function.checkdate.php

And You also need to add your date format (ex : dd/mm/yyyy) in the "Validation Extra" field when you edit your Textbox component.

Hope this help.

N.B : to add @ next releases ;)
Last Edit: 13 years 6 months ago by cameleons.
The administrator has disabled public write access.

Re:Date Validation 13 years 5 months ago #12004

  • Someone
  • Someone's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 1
There is a backslash in the original code....blame the forum soft...or the people that don't fix it...

i added an additional backslash so if some decides to fix that buggy forum soft the code will be wrong. :blink: :blink:

cheers
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!