jsverification.js example
//------------------FOR DEMO USE ONLY----------------------------------
//-------- Copyright by Artem Saveliev artem@savelev.com --------------
//---------------------------------------------------------------------
function validatemoney(num) {
var result;
var re;
num = num.toString().replace(/\$|\,|[^\.0-9\-]/g,'');
if(isNaN(num)) num = "0";
if (num.length == 0 || num == "0") return "";
re = /^(-)?(\d*)?(\.(\d*))?$/
matches = re.exec(num)
if (matches == null) return "";
result = matches[1]+"$";
num = matches[2];
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));
if (matches[2] != "") result += num; else result += "0";
if (matches[3] != null && matches[4] != null) {
cents = new Number("0."+matches[4].substr(0,4));
if (cents != 0){
cents = Math.round(cents*10000);
centstxt = cents.toString();
if(cents < 1000) centstxt = "0" + centstxt;
if(cents < 100) centstxt = "0" + centstxt;
if(cents < 10) centstxt = "0" + centstxt;
centstxt = centstxt.toString().replace(/0*$/g,'');
result += "."+centstxt;
}
}
return result;
}
function validateint(num)
{
num = num.toString().replace(/[^0-9]/g,'');
return num;
}
function validatefloat(num)
{
num = num.toString().replace(/[^\d\.]/g,'').replace(/\.\d+\..*/g,'');
if (num.length == 0) return "";
mynum = new Number();
mynum = num;
numint = Math.floor(mynum);
fraction = mynum - numint;
if (numint == 0) return fraction.toString(); else return num;
}
function validatephone(num){
var straightphonepat=/^\d{10}$/
var removedelim =/[\.,\-,\s,\(,\)]/g
if (num.replace(removedelim,"").match(straightphonepat)) num = num.replace(removedelim,"")
if (num.match(straightphonepat)) {
num = num.substr(0,3) + "-" + num.substr(3,3) + "-" + num.substr(6,4);
}
return num;
}
function validatedate(num)
{
var straightdatepat=/\d{6}/
if (num.match(straightdatepat)) {
num = num.substr(0,2) + "/" + num.substr(2,2) + "/" + num.substr(4,2);
}
var mdate;
var s;
s = "";
i = Date.parse(num);
if (isNaN(i)) return "";
mdate = new Date(i);
year = mdate.getFullYear();
if (year >= 1900 && year < 1950) year = mdate.getFullYear() + 100;
else if (year < 1900) year = Date.Year;
return (mdate.getMonth()+1) + "/" + mdate.getDate() + "/" + year;
}
function limittextarea(area,value) {
var additional = area.value.match(/\n|\r/g);
if (additional!=null) additional = additional.length
if (area.value.length+additional > value) area.value=area.value.substring(0, value-additional);