function url_validate(userUrl){

var regUrl = /^(((ht|f){1}((tp|tps):[/][/]){1})|((www.){1}))[-a-zA-Z0-9@:%_\+.~#?&//=]+$/;

return regUrl.test(userUrl);

}

function alnucheck(str){

var myRegxp = /^([a-zA-Z0-9_-]+)$/;

return myRegxp.test(str);

}

function checkBlank(){

if(document.getElementById('longName').value=="" || document.getElementById('longName').value=="http://"){

alert('Please write a URL to shorten');

document.getElementById('longName').focus();

return false;

}

if(document.getElementById('shortName').value==""){

alert('Please write a wanted short url');

document.getElementById('shortName').focus();

return false;

}

if(!url_validate(document.getElementById('longName').value)){

alert('Please write a valid URL. Start it with http://');

document.getElementById('longName').focus();

return false;

}

if(!alnucheck(document.getElementById('shortName').value)){

alert( "You can only use alphabets, numbers, hyphen and underscore for short name." );

document.getElementById('shortName').focus();

return false;

}

document.getElementById("URLForm").submit();

return true;

}
