home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2003 July
/
CMCD0703.ISO
/
Software
/
Freeware
/
Programare
/
bugzero
/
jsp
/
script
/
utils.js
< prev
Wrap
Text File
|
2003-01-21
|
2KB
|
74 lines
<!-- Begin
function assert(condition, msg) {
if (condition == false) {
alert (msg)
return false;
} else {
return true;
}
}
function isEmpty(input, msg) {
trim(input);
if(input.value.length==0) {
alert (msg)
return true;
} else {
return false;
}
}
function validEmailList(input) {
trim(input);
var str = input.value;
if (str.length == 0) {
return true;
}
var start = 0;
var end = 0;
for (var i=0; i<str.length; i++) {
var c = str.charAt(i);
if (c == ';' || c == ' ' || c == ',') {
end = i;
if (!validEmail(str.substring(start, end))) return false;
start = end+1;
}
}
return validEmail(str.substring(start, str.length));
}
function validEmail(str) {
_trim(str);
if(str.length == 0) {
return true;
} else {
var regEmail = /^[^@]+@[^@]+.[a-z]{2,}$/i;
if (str.search(regEmail)==-1) {
alert ("Email address '"+ str+"' is not valid!")
return false;
}
return true;
}
}
function trim(input) {
var str = input.value;
while(''+str.charAt(0)==' ') {
str=str.substring(1,str.length);
}
while(''+str.charAt(str.length-1)==' ') {
str=str.substring(0,str.length-1);
}
input.value=str;
}
function _trim(str) {
while(''+str.charAt(0)==' ') {
str=str.substring(1,str.length);
}
while(''+str.charAt(str.length-1)==' ') {
str=str.substring(0,str.length-1);
}
}
// End -->