Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Alessandro Pellizzari Newsgroups: it.comp.www.php Subject: Re: espressione regolare Date: 28 Nov 2015 22:01:55 GMT Lines: 31 Message-ID: References: <2015112817284421718@mynewsgate.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net egdNP/nJH22RUQsVzNKXegqeaL1yElrWU56IWxi74Kzs9tI3Y= Cancel-Lock: sha1:eFEUZIP6vWkNQKSkIGGx2PdrM9o= User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com it.comp.www.php:20111 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.