Hi Rick. I'm using Jorn's Validation plugin with CF 7.0. But for currency
fields used this example for brazilian values(251.251,84):
<input

   id="conta__coj_vr_capital_social"

   name="conta__coj_vr_capital_social"

   type="text"

   size="50"

   value="#LsCurrencyFormat(coj_vr_capital_social,'none')#"

   onkeypress="return (
String.fromCharCode(window.event.keyCode).search(/[0-9]/i)
-1 );"

   onKeydown="FormataMoeda(this,16,event,2)"

   maxlength="16" />


onkeypress allows user to insert only numbers and onkeydown formats the
field inserting points and comma.

FormataMoeda script:

// funcoes relacionadas a formatacao de campo MOEDA/VALOR/MONEY
function Limpar(valor, validos) {
   // retira caracteres invalidos da string
   var result = "";
   var aux;
   for (var i=0; i < valor.length; i++) {
       aux = validos.indexOf(valor.substring(i, i+1));
       if (aux>=0) {
           result += aux;
       }
   }
   return result;
}

//Formata nĂºmero tipo moeda usando o evento onKeyDown
function FormataMoeda(campo,tammax,teclapres,decimal) {
   var tecla = teclapres.keyCode;
   vr = Limpar(campo.value,"0123456789");
   tam = vr.length;
   dec=decimal

   if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

   if (tecla == 8 ){ tam = tam - 1 ; }

   if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <=
105 )
   {

       if ( tam <= dec ){ campo.value = vr ; }

       if ( (tam > dec) && (tam <= 5) ){
           campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam -
dec, tam ) ;
       }
       if ( (tam >= 6) && (tam <= 8) ){
           campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam -
5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
       }
       if ( (tam >= 9) && (tam <= 11) ){
           campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam -
8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;

       }
       if ( (tam >= 12) && (tam <= 14) ){
           campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam -
11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) +
"," + vr.substr( tam - dec, tam ) ;
       }
       if ( (tam >= 15) && (tam <= 17) ){
           campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam -
14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) +
"." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;
       }
   }

}

//funcao retorna somente numeros para uma string
function soNumeros(n)
{
   var s = String(n);
   var n2 = String();
   for(var i = 0; i < s.length; i++) {
       var ss = s.substr(i,1);
       if(ss >= '0' && ss <= '9') { n2 = n2 + ss; }
       }
   while (n2.length>1 && n2.charAt(0) == "0") n2=n2.substr(1,n2.length);
   return n2;
}


It's a suggestion.

Cheers


2007/3/11, Rick Faircloth <[EMAIL PROTECTED]>:


Thanks for the tip, Daemach, but I'm afraid I don't have that
js script... I'm still on CF 4.5...

However, if the "CF_checknumber" function only validates
numbers,  it won't be of much use, because Jorn's Validation plug-in
has built-in validation of numbers.

Rick

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Daemach
Sent: Sunday, March 11, 2007 3:25 AM
To: [email protected]
Subject: Re: [jQuery] Adding Currency Validation to Jorn's Validation
Plug-In


/cfide/scripts/cfforms.js might give you some ideas.  Specifically
function
_CF_checknumber(object_value, required).


Rick Faircloth wrote:
>
> Hi, all.
>
> I was wondering if anyone knew how to add
> a currency validation function (US Dollars) to Jorn's Validation plug-in
> at www.bassistance.de?
>
> I've tried adding a method, but I don't know enough
> about adding a method or about Regex's to be able to
> get it working.
>
> Any clues anyone?
>
> Thanks,
>
> Rick
>





_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to