Wednesday, April 21, 2010

JS form validation1

function validate_frm()
{
var URL = document.frm.url.value;
var URL_PARTS =new Array();
URL_PARTS = URL.split('.');
len = URL_PARTS.length
var file_ext = URL_PARTS[len-1];
var arrtitle = new Array();
arrtitle = document.getElementById('title').value.split(" ");
var len = arrtitle.length-1;

var flag1=0;
var iChars3 = "special charssssss";

UL1 = document.frm.url.value;

if(!isValidURL(document.frm.url.value))
{
alert("Please enter valid URL");
document.frm.url.focus();
return false;
}

if( UL1.substring(0,7) != "http://" )
{
alert("Please enter URL with http://");
document.frm.url.focus();
return false;
}

if(file_ext.toLowerCase() != "mp3")
{
alert("Please use mp3 file only.");
document.frm.url.focus();
return false;
}

if(document.frm.title.value=='')
{
alert("Please enter title");
document.frm.title.focus();
return false;
}
else if( ( arrtitle[0] == "") || ( arrtitle[0] == null) )
{
alert("please remove the empty space at begin of the title");
document.getElementById('title').focus();
return false;
}
else if( (arrtitle[len] == "") || (arrtitle[len] == null) )
{
alert("please remove the empty space at end of the title");
document.getElementById('title').focus();
return false;
}
else if( document.getElementById('title').value != "" )
{
for (var i = 0; i < document.getElementById("title").value.length; i++)
{
if (iChars3.indexOf(document.getElementById("title").value.charAt(i)) != -1)
{
flag1=1;
}
}

if(flag1==1)
{
alert ("Title can not accept the following "+iChars3+" characters.");
document.getElementById('title').focus();
return false;
}
}
return true;
}

No comments:

Post a Comment