Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.www.php > #20111
| From | Alessandro Pellizzari <shuriken@amiran.it> |
|---|---|
| Newsgroups | it.comp.www.php |
| Subject | Re: espressione regolare |
| Date | 2015-11-28 22:01 +0000 |
| Message-ID | <dbumijFml5bU1@mid.individual.net> (permalink) |
| References | <2015112817284421718@mynewsgate.net> |
Il Sat, 28 Nov 2015 17:28:44 +0000, Halnow ha scritto:
> volevo ottenere un'espressione in grado di verificare se l'input utente
> è composto da 1 a 10 cifre seguito da due cifre decimali...
> 0,00 1,20 12,53 1526,60 etc...
La parte decimale è facoltativa o obbligatoria? Dalla tua RE sembra
facoltativa.
> if (!preg_match("/^d{1,10}(\,\d{2})?$/",$input_utente)) {
Sul primo d manda il backslash: \d
Sulla virtola non serve il backslash: (,\d{2}...)
preg_match restituisce 0 se non matcha e false se c'è un errore nella
regexp. Se casti tutto a bool non saprai mai se c'è stato un errore o se
non ha trovato il match. L'if giusto è
$res = preg_match...;
if (false === $res) {
// errore
} else if (0 === $res) {
// no match
} else {
// match
}
Bye.
Back to it.comp.www.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
espressione regolare "Halnow" <21718invalid@mynewsgate.net> - 2015-11-28 17:28 +0000
Re: espressione regolare Alessandro Pellizzari <shuriken@amiran.it> - 2015-11-28 22:01 +0000
Re: espressione regolare Alessandro Pellizzari <shuriken@amiran.it> - 2015-11-28 22:03 +0000
Re: espressione regolare "Halnow" <21718invalid@mynewsgate.net> - 2015-11-29 09:10 +0000
Re: espressione regolare Alessandro Pellizzari <shuriken@amiran.it> - 2015-11-29 09:21 +0000
Re: espressione regolare "Halnow" <21718invalid@mynewsgate.net> - 2015-11-29 11:40 +0000
csiph-web