home *** CD-ROM | disk | FTP | other *** search
/ 202.53.64.216 / 202.53.64.216.tar / 202.53.64.216 / janahitha / func.js < prev    next >
Text File  |  2004-11-26  |  5KB  |  270 lines

  1. function isempty(val)
  2. {
  3.     flag = false;
  4.     if(val.value=="")
  5.         flag = true;
  6.     else
  7.     {
  8.         flag = true;
  9.         for(i=0;i<val.value.length;i++)
  10.             if(val.value.substr(i,1)!=" ") flag = false;
  11.     }
  12.     if(flag==true)
  13.     {
  14.         alert("Enter The Column Value");
  15.         return true;
  16.     }
  17.     else
  18.         return false;
  19. }
  20.  
  21. function isurl(val)
  22. {
  23.     theinput = val.value;
  24.     thelength = theinput.length;
  25.     if(thelength>0)
  26.     {
  27.         loc = 0;
  28.         for(i=0;i<thelength-2;i++)
  29.         {
  30.             thestr = theinput.substr(i,3);
  31.             if(thestr=="://") loc = i;
  32.         }
  33.         isnot = "`!@$^*(){}[]\|;',<>";
  34.         url = true;
  35.         if(loc==0) url = false;
  36.         for(i=0;i<thelength;i++)
  37.             for(j=0;j<isnot.length;j++)
  38.                 if((theinput.substr(i,1)==isnot.substr(j,1))||(theinput.substr(i,1)=='"')) url = false;
  39.         if(url==true) 
  40.             return true;
  41.         else
  42.         {
  43.             alert("Enter A Valid URL");
  44.             return false;
  45.         }
  46.     }
  47.     else
  48.         return true;
  49. }
  50.  
  51. function isnum(val)
  52. {
  53.     if(isempty(val))
  54.         return false;
  55.     num = true;
  56.     theinput = val.value;
  57.     theinput.replace(" ",""); 
  58.     thelength = theinput.length;
  59.     for(i=0;i<thelength;i++)
  60.     {
  61.         thechar = theinput.substring(i,i+1);
  62.         if(thechar<"0" || thechar>"9") num = false;
  63.     }
  64.     if(num==false)
  65.     {
  66.         alert(" Please Enter A Numeric Value...");
  67.         return false;
  68.     }
  69.     else
  70.         return true;
  71. }
  72.  
  73. function ismoney(val)
  74. {
  75.     var theinput = val.value; 
  76.     var thelength = theinput.length;
  77.     var money = true;
  78.  
  79.     if(isempty(val))
  80.         return false;
  81.     for(i=0;i<thelength;i++)
  82.     {
  83.         thechar = theinput.substr(i,1);
  84.         if((thechar<"0" || thechar>"9") && (thechar!=".")) money = false;
  85.     }
  86.     if(money==false)
  87.     {
  88.         alert("Enter A Valid Currency Value");
  89.         return false;
  90.     }
  91.     else
  92.         return true;
  93.     
  94. function ispin(val)
  95. {
  96.     if(val.value=="")
  97.         return true;
  98.     var theinput = val.value; 
  99.     var thelength = theinput.length;
  100.     var pincode = true;
  101.     if(thelength!=6) 
  102.         pincode = false;
  103.     else
  104.         for(i=0;i<6;i++)
  105.         {
  106.             thechar=theinput.substring(i,i+1);
  107.             if(thechar<"0" || thechar>"9") pincode=false;
  108.         }
  109.     if(pincode==false)
  110.     { 
  111.         alert("Not A Valid Pin Code...Enter A 6-digit Pin Code");
  112.         return false;
  113.     }
  114.     else
  115.         return true;
  116. }
  117.  
  118. function iszip(val)
  119. {
  120.     if(isempty(val))
  121.         return false;
  122.     var theinput = val.value; 
  123.     var thelength = theinput.length;
  124.     var pincode = true;
  125.     if(thelength!=5) 
  126.         pincode=false;
  127.     else
  128.         for(i=0;i<5;i++)
  129.         {
  130.             thechar = theinput.substring(i,i+1);
  131.             if(thechar<"0" || thechar>"9") pincode = false;
  132.         }
  133.     if(pincode==false)
  134.     { 
  135.         alert("Not a valid Pin Code...Enter again");
  136.         return false;
  137.     }
  138.     else
  139.         return true;
  140. }
  141.  
  142. function islogin(val)
  143. {
  144.     if(isempty(val))
  145.         return false;
  146.     var theinput = val.value; 
  147.     var thelength = theinput.length;
  148.     var login = true;
  149.     if(val.value=="")
  150.         return true;
  151.     else
  152.     {
  153.         if(thelength<6) login=false;
  154.         if(login==false)
  155.         { 
  156.             alert("Minimum 6 characters are allowed...Enter again");
  157.             return false;
  158.         }
  159.         else
  160.             return true;
  161.     }
  162. }
  163.  
  164. function isphone(val)
  165. {
  166.     if(isempty(val))
  167.         return false;
  168.     theinput = val.value; 
  169.     phonenumber = true;
  170.     for(i=0;i<theinput.length;i++)
  171.     {
  172.         thechar = theinput.substring(i,i+1);
  173.         if(thechar<"0" || thechar>"9")
  174.         {
  175.             if(thechar!=" " && thechar!="-" && thechar!="+")  phonenumber=false;
  176.         }
  177.     }
  178.     if(phonenumber==false)
  179.     { 
  180.         alert("Not a valid Phone Number...Enter again");
  181.         return false;
  182.     }
  183.     else
  184.         return true;
  185. }
  186.  
  187. function isemail(val)
  188. {
  189.     if(isempty(val))
  190.         return false;
  191.     theinput = val.value; 
  192.     theemail = true;
  193.     thelength = theinput.length;
  194.     if(thelength<5) theemail = false;
  195.     for(i=0;i<thelength;i++)
  196.     {
  197.         thechar=theinput.substr(i,1).toUpperCase();
  198.         if(!(thechar>="A" && thechar<="Z"))
  199.             if(!(thechar>="0" && thechar<="9"))
  200.                 if(thechar!="." && thechar!="@" && thechar!="_" && thechar!="-")
  201.                     theemail = false;
  202.     }
  203.     atloc1 = 0; atloc2 = 0; decloc = 0;
  204.     atloc1 = theinput.indexOf("@");
  205.     atloc2 = theinput.lastIndexOf("@");
  206.     decloc = theinput.indexOf(".");
  207.     if(atloc1==0 || decloc==0 || atloc1!=atloc2 || Math.abs(atloc1-decloc)<2 || decloc==(thelength-1)) theemail = false;
  208.     if(theemail==false)
  209.     { 
  210.         alert("Not A Valid E-mail Address...Enter Again");
  211.         return false;
  212.     }
  213.     else
  214.         return true;
  215. }
  216.  
  217. function issame(val1,val2)
  218. {
  219.     sameval=true;
  220.     theinput1 = val1.value;
  221.     theinput2 = val2.value;
  222.     thelength1 = theinput1.length;
  223.     thelength2 = theinput2.length;
  224.     if(thelength1!=thelength2) 
  225.         sameval = false;
  226.     else
  227.     {
  228.         if(theinput1!=theinput2) sameval=false;
  229.     } 
  230.     if(sameval==false)
  231.     { 
  232.         alert("Invalid Password...Enter again");
  233.         return false;
  234.     }
  235.     else
  236.         return true;
  237. }
  238.  
  239. function isccno(val)
  240. {
  241.     if(!(isnum(val)))
  242.         return false;
  243.     isccnum = false;
  244.     total = 0;
  245.     theinput = val.value;
  246.     thelength = theinput.length;
  247.     for(i=thelength-1;i>=1;i-=2)
  248.     {
  249.         total = total + parseInt(theinput.substr(i,1),10);
  250.         tmp = parseInt(theinput.substr(i-1,1)) * 2;
  251.         if(tmp<10)
  252.             total += tmp;
  253.         else
  254.             total += (tmp%10)+((tmp-(tmp%10))/10);
  255.     }
  256.     if(thelength%2==1)
  257.         total += parseInt(theinput.substr(0,1));
  258.     if(total%10==0)
  259.         isccnum=true; 
  260.  
  261.     if(isccnum==false)
  262.     {
  263.         alert("Not a valid CC Number...Enter again");
  264.         return false;
  265.     }
  266.     else
  267.         return true;
  268. }
  269.