Category Archives: JavaScript

Showing the Processing/Loading image

I came across a good code sample while surfing for showing the Loading/Processing  image on the VisualForce Page.

You can find it at: http://force.siddheshkabe.co.in/2009/10/displaying-please-wait-ajax-animation.html

Regex for AlphaNumeric password validation

Regular Expression for validating the string

(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,20})$

The above RegEx requires at least one digit, at least one alphabetic character, no special characters, and from 8-20 characters in length.

JavaScript: Number to Currency format conversion function

JavaScript for converting string to currency format.

function FormatToCurrency(num)
{
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents < 10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}