Ciao.
Come si può validare ad esempio i
gg della settimana
da 01 a 07
mesi dell'anno
da 01 a 12
anno
da 2000 a mettiamo ad essere previdenti 2050
(insomma in questo caso 'a' sarebbe da valutare )
![]()
Ciao.
Come si può validare ad esempio i
gg della settimana
da 01 a 07
mesi dell'anno
da 01 a 12
anno
da 2000 a mettiamo ad essere previdenti 2050
(insomma in questo caso 'a' sarebbe da valutare )
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
scusate naturalmente i gg iniziano da
da 01 a 31
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Peccato per il 32 ;($isValid=(bool)preg_match('/[0-3]{1}[0-9]{1}/','01');//true
var_dump($isValid);
echo "
";
$isValid2=(bool)preg_match('/[0-3]{1}[0-9]{1}/','07');//true
var_dump($isValid2);
echo "
";
$isValid3=(bool)preg_match('/[0-3]{1}[0-9]{1}/','08');//true
var_dump($isValid3);
echo "
";
$isValid4=(bool)preg_match('/[0-3]{1}[0-9]{1}/','31');//true
var_dump($isValid4);
echo "
";
$isValid4=(bool)preg_match('/[0-3]{1}[0-9]{1}/','20');//true
var_dump($isValid4);
echo "
";
$isValid5=(bool)preg_match('/[0-3]{1}[0-9]{1}/','32');//true
var_dump($isValid5);
echo "
";
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Mah cercando nel vasto web
la cosa sembrerebbe fattibile
con un misto di regex e robetta
varia che tra l'altro valida pure
se un mese è di 31 30 o 28/9 gg
E solo con le regex ni pare dura![]()
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Ciao, scusa se interrompo il tuo soliloquio ma non puoi usare checkdate?![]()
http://se2.php.net/manual/it/function.checkdate.php
A chi può servire :
Ogni suggerimento è il benvenutoCodice PHP:
$day = (int)'29';
$month = (int)'02';
$year= (int)'2000';
//true
$day = (int)'29';
$month = (int)'02';
$year= (int)'2001';
//false
$day = (int)'28';
$month = (int)'02';
$year= (int)'2007';
//true
$day = (int)'31';
$month = (int)'11';
$year= (int)'2007';
//false
$isValidDayMonth= true;
$arrayLookup = array('1'=>'31',
'3'=>'31',
'4'=>'30',
'5'=>'31',
'6'=>'30',
'7'=>'31',
'8'=>'31',
'9'=>'30',
'10'=>'31',
'11'=>'30',
'12'=>'31');
if($day !== 0 && $month !== 0 && $year !== 0 ){
if(isset($arrayLookup[$month]) && $day <= 31){
//check if month value and day value agree
if($day >= $arrayLookup[$month]){
//bad day for the month
$isValidDayMonth= false;
}
}
//check february day
if ($month === 2){
if($day > 29){
//bad day for the month
$isValidDayMonth= false;
}
elseif($day === 29){
if (($year % 4 == 0) && ($year % 100 != 0) || ($year % 400 == 0)) {
// year div by 4 and ((not div by 100) or div by 400) ->ok
$isValidDayMonth= true;
}
else{
$isValidDayMonth= false;
}
}
}
}
var_dump($isValidDayMonth);
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Originariamente inviato da nicola75ss
Ciao, scusa se interrompo il tuo soliloquio ma non puoi usare checkdate?![]()
http://se2.php.net/manual/it/function.checkdate.php
PP ero così impegnato con me stesso
che non avevo visto il post![]()
Ps.
Cq adesso devo risolvere come validare
mese e anno
e
anno
Pensandoci un attimo potrei
gestire il tutto prendendo spunto
dal mio masterpiecesenza regex.
Che ne pensi ?
![]()
PS
Checkdate proprio non l'avevo vista
e sinceramente non era saltata
fuori neanche dopo riterate ricerche su google
ma forse sbagliavo chiave di ricerca![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Ma giorno,mese e anno come vengono passati?
Hai tre campi di tipo testo, tre menù a tendina o cosa?