Saturday, May 12, 2012

Check Validation using Javascript


Hello,

I face the many problem when I validate form using javascript. here i share you a validation functions for you guys...


// empty check validation
function check_empty(text) {
   if (text == null || text == "" || text == "0.00")
      return false;
   return true;
}



// number validation
function isNumber(inputStr) {
   for (var i = 0; i < inputStr.length; i++) {
      var oneChar = inputStr.substring(i, i + 1)
      if (oneChar < "0" || oneChar > "9")
         return false;
      }
   return true;
}

// float validation
function isFloat(inputStr) {
var count_dot=0;
   for (var i = 0; i < inputStr.length; i++) {
      var oneChar = inputStr.substring(i, i + 1)
      if (oneChar < "0" || oneChar > "9")
if(oneChar != "." || count_dot == 1)
{
return false;
}
else{
count_dot=1;
}
      }
   return true;
}