29/giu/2007

Validazione campi Lotus

Una formula per controllare che un campo di tipo testo contenga in realtà solo cifre.
Da mettere nell'input translation del campo:

t := @ThisValue;
n := @TextToNumber("1" + t);
res := @If(@IsError(n); t; @If(@Length(@Text(n)) = @Length(t) + 1; ""; t));
@If(res!=""; @Failure("Campo non numerico"); @Success)

6 Comments:

cyberflaz ha detto...

Ma non è più semplice usare un @IsNumber?!?

Michele Malaguti ha detto...

Non esattamente perchè ad esempio:
@IsNumber("18") = 0
@IsNumber(18) = 1
Se voglio controllare che un campo testuale contenga solo numeri, posso farlo con @IsNumber ma dovrei prima convertire il valore da testo a numerico. Nota però che:
@TextToNumber("18acbd")=18 !!

Cristian D'Aloisio ha detto...

Grazie per la spiegazione semplice e chiara!

Anonimo ha detto...

it doesn't handle negative numbers. what about to put "1" at the end?

Michele Malaguti ha detto...

To handle negative numbers, maybe the simplest solution is to replace the statement:
t := @ThisValue;
with:
t := @if(@Begins(@ThisValue; "-"); @Right(@ThisValue; "-"); @ThisValue);

Anonimo ha detto...

Perche non:)