Come faccio a controllare che l' utente ha inserito correttamente un numero con la virgola per es. 50,00
Grazie terrix![]()
Come faccio a controllare che l' utente ha inserito correttamente un numero con la virgola per es. 50,00
Grazie terrix![]()
in che senso?Originariamente inviato da terrix
Come faccio a controllare che l' utente ha inserito correttamente un numero con la virgola per es. 50,00
Grazie terrix![]()
che sia un numero:
http://it.php.net/is-numeric
Come faccio a controllare che l' utente ha inserito correttamente un numero con la virgola per es. 50,00che sia un numero:![]()
Che ci sia la virgola![]()
$ce = strstr($variabila,",");
if($ce) {
echo"ok";
} else {
echo"metti la virgola birbante!";
}
così?
Originariamente inviato da terrix
![]()
Che ci sia la virgola![]()
![]()
Vedi che array prenderà tutti i numeri che avranno la virgolaCodice PHP:
preg_match_all("|[0-9]{1,},[0/9]{1,}|", $mia_stringa, $array);
if($array) print "c'ha la virgola!"; else print "non ce l'ha...";
OPPPPPPPPPURE
controlla che $numero sia uguale anche se arrotondatoCodice PHP:
if(round($numero) == $numero) print "non c'ha la virgola";
(che trucchetto)
![]()
" guarda bene sopra... leggi, c'è scritto che deve essere un numeroOriginariamente inviato da moonx2004
$ce = strstr($variabila,",");
if($ce) {
echo"ok";
} else {
echo"metti la virgola birbante!";
}
così?"
Questa la dà valida?![]()
Grandiosi ragazzi![]()
adesso provo subito
Grazie![]()
terrix
Non riesco a risolvere, piu' che altro non capisco la logica dello script {la vostra si, basta guardare gli avatar
}.
Prima di passare alle RegExp con Javascript mi guardate lo script { se non vi dispiace} cosi' almeno mi torna un codice piu' pulito?
#---------------------------------#
<?php
$tabadd=true;
$tabthank=false;
$msg=$Reg_MSG;
$red="#FF0000";
$black="#000000";
$fontc=$black;
$date=date("his");
$code=$date+2*$d;
if($reg){
$checkname=(strlen($user_name));
$sqlusercheck=mysql_query("select username from loginwa_user where username='$user_name' ");
if(!empty($sqlusercheck)){
$numcheck=mysql_num_rows($sqlusercheck);
}
$sqlemailcheck=mysql_query("select email from loginwa_user where email='$reg_email' ");
if(!empty($sqlemailcheck)){
$sqlnumemail=mysql_num_rows($sqlemailcheck);
}
$checkname=(strlen($user_name));
$invalidname=($checkname < 6);
if($invalidname){
$msg=$Reg_Smalname_Error;
$fontc=$red;
}
if(empty($user_name)){
$msg=$Reg_Name_Error;
$fontc=$red;
}
if(empty($pass)){
$msg=$Reg_Pass_Error;
$fontc=$red;
}
if(empty($reg_email)){
$msg=$Reg_Email_Error;
$fontc=$red;
}
if(empty($value)){
$msg=$Reg_Value_Error;
$fontc=$red;
}
else if($sqlnumemail==1){
$msg=$Reg_Email_Exists;
$fontc=$red;
}
else if($numcheck==1){
$msg=$Reg_Name_Exists;
$fontc=$red;
}
else if($pass!=$pass_repeat){
$msg=$Reg_Pass_Agin_Error;
$fontc=$red;
}
else if(empty($newsletter)){
$nl="no";
$msg=$Reg_Yes_Error;
$fontc=$red;
}else{
$nl="yes";
}
if(preg_match("/ /",$user_name)){
$msg=$Reg_Blank_Error;
}
else if( ($numcheck==0) && ($sqlnumemail==0) && ($user_name) && ($pass=$pass_repeat) && ($newsletter) && ($value) && (!$invalidname)){
$sql =mysql_query("INSERT INTO loginwa_user ( `userid` , `username` , `passwd` , `email` , `fcode` , `nl` , `value`, `adddate` )
VALUES ( '', '$user_name', '$pass', '$reg_email', '$code', '$nl', '$value',NOW())");
$user_id=mysql_insert_id();
$link="$host/activate.php?id=$user_id&username=$user_name";
$Mail_MSG="$hello $user_name\n$Reg_Mail_MSG\nUsername:$user_name\n$R eg_Code$code\n$link\n\n$Reg_Mail_ThanknsMSG\n$host ";
$send_mail= mail ($reg_email,$Reg_Mail_supject,$Mail_MSG, "From: $adminmail");
$msg=$Reg_Succ_MSG;
$tabthank=true;
$tabadd=false;
}
}
?>
#-----------------------------------------#
la variabile e' $value [{che fantasia} direte voi, ma mi e' venuta cosi']
Fatemi sapere
terrix
Perchè preg_match_all() ?Originariamente inviato da PaTeR
![]()
Vedi che array prenderà tutti i numeri che avranno la virgolaCodice PHP:
preg_match_all("|[0-9]{1,},[0/9]{1,}|", $mia_stringa, $array);
if($array) print "c'ha la virgola!"; else print "non ce l'ha...";
![]()
Addio Aldo, amico mio... [03/12/70 - 16/08/03]