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:
Ma non è più semplice usare un @IsNumber?!?
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 !!
Grazie per la spiegazione semplice e chiara!
it doesn't handle negative numbers. what about to put "1" at the end?
To handle negative numbers, maybe the simplest solution is to replace the statement:
t := @ThisValue;
with:
t := @if(@Begins(@ThisValue; "-"); @Right(@ThisValue; "-"); @ThisValue);
Perche non:)
Post a Comment