home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 December
/
Chip_1999-12_cd.bin
/
internet
/
ruceni
/
validate.js
< prev
next >
Wrap
Text File
|
1999-11-02
|
4KB
|
190 lines
//*****************************************************************
function setSel(elem,n) {
for(var i=0; i<elem.options.length; i++) {
if (elem.options[i].value==n) {
elem.options[i].selected=true;
return;
}
}
}
//******************************************************************
function valSelect(elem,nazev,item) {
// elem - element Select formulß°e
// nazev - nßzev selektu
// item - kterß polo₧ka v po°adφ nemß b²t vybrßna
// - -1 mohou b²t vybrßny vÜechny
var poc = elem.length;
if(elem.selectedIndex<0) {
alert("Nebyla vybrßna ₧ßdnß polo₧ka v nabφdce "+nazev);
elem.focus();
// elem.select();
return false;
}
if(item>-1) {
ind=elem.selectedIndex;
if(ind==item) {
alert("Nebyla vybrßna ₧ßdnß polo₧ka v nabφdce "+nazev);
elem.focus();
// elem.select();
return false;
}
}
return true;
}
//*****************************************************************
function valPsc(elem) {
if(!valText(elem,"PS╚")) return false;
var s=""+elem.value;
if(!isIn(s,"0123456789") ) {
alert("Polo₧ka m∙₧e obsahovat jen Φφslice bez mezer");
elem.focus();
elem.select();
return false;
}
if(s.length!=5) {
alert("PS╚ m∙₧e obsahovat pouze 5 Φφslic");
elem.focus();
return false;
}
return true;
}
//*****************************************************************
function valCislo(elem, nazev) {
if(!valText(elem,nazev)) return false;
var s=""+elem.value;
if(!isIn(s,"0123456789") ) {
alert("Polo₧ka m∙₧e obsahovat jen Φφslice bez mezer");
elem.focus();
elem.select();
return false;
}
return true;
}
//*****************************************************************
function valCastka(elem) {
var s = elem.value;
var i= parseInt(s);
if( !(isIn(s,"0123456789,") && (i>=0 && s!="") && count(s,',')<=1) ) {
alert("Polo₧ka m∙₧e obsahovat jen Φφslice bez mezer\n a jednu desetinnou Φßrku.");
elem.focus();
elem.select();
return false;
}
return true;
}
//*****************************************************************
function valText(elem,nazev) {
var s=elem.value;
if (s.length==0 || count(s, ' ')==s.length) {
alert("Nenφ zadanß polo₧ka: "+nazev);
elem.focus();
elem.select();
return false;
} else
return true;
}
//*****************************************************************
function isIn(m, validChars) {
var s=m;
found=true;
for(i=0; found && i<s.length; i++) {
found=false;
for(j=0; !found && j<validChars.length; j++) {
found= found || s.charAt(i)==validChars.charAt(j);
}
}
return found;
}
//*****************************************************************
function count(s,charSet) {
counter=0;
for(i=0; i<s.length; i++) {
if(charSet.indexOf(s.charAt(i)) > -1)
counter++;
}
return counter;
}
//***************************************************
function Split2(s,c) {
var arr= new Array;
pre=0;
for(n=0; (now=s.indexOf(c,pre))!=-1; n++) {
arr[n]=s.substring(pre,now);
pre=now+1;
}
arr[n]=s.substring(pre,s.length);
return arr;
}
//***************************************************
function valDatum(dat) {
d=0;
m=0;
r=0;
t1=0;
t2=0;
sep=".";
ok1=true;
var aDat = new Array();
aDat=Split2(dat,sep);
if(!(aDat.length==3))
ok1=false;
d=parseInt(aDat[0],10);
r=aDat[2];
m=parseInt(aDat[1],10);
if(m<1 || m>12)
ok1=false;
if(d<1 || d>31)
ok1=false;
if(m==2 && d>29)
ok1=false;
if(m>1) {
if("46911".indexOf(m)>-1 && d>30)
ok1=false;
}
if(!(r.length==4))
ok1=false;
if(!ok1)
alert("V datumu je chyba - "+dat);
return ok1;
}
var set_numeric = "0123456789";
var set_alfa_numeric = "0123456789" + "aΣßbcΦδd∩eΘ∞fghiφjkl╛mn≥o≤÷pqr°sÜt¥u·∙ⁿvwxy²z " + "A─┴BC╚╦D╧E╔╠FGHI═JKL╝MN╥O╙╓PQR╪SèTìU┌┘VWXY▌Z";
function ChkInput(frm, nazev, allow_set, pov )
{
var i,c,val,len,res;
val = frm.value;
if ((val=='') && (pov==1)) {
alert("Polo₧ka < " + nazev + " > je povinnß ");
frm.focus();
frm.select();
return(false);
}
len = val.length;
for(i=0;i<len; i++) {
c = val.charAt(i);
res = allow_set.indexOf(c);
if(res < 0) {
alert('Chyba v polo₧ce < ' + nazev + ' > \n\nNepovolen² znak [' + c + ']');
frm.focus();
frm.select();
return(false);
}
}
return(true);
}
//***************************************************