bazz
05-29-2012, 04:16 PM
Hi been away for a while and have gone a bit rusty.
i am running a form where the url is to be entered. I want to clear out the http:// and the www., which if done, would then show the remainder of the url in the textbox.
I can seem to recall how to wrap the unwanted set of characters into the script.
what have I forgotten?
//check the web_url
var val = document.getElementById("myForm").web_url.value;
val = val.replace(/^\\s+|\\s+\$/g,""); // strip all leading and trailing spaces
val = val.replace(/\\s{2,}/g," "); // convert multiple spaces into a single space
val = val.replace (/[^a-z\\s\\-\.]/gi,""); // strip the characters from the url that are not allowed
val = val.replace (/http/gi, "") // strip the http
val = val.replace (/www./gi, "") // strip the www.
document.getElementById("myForm").web_url.value = val; // write it back to the field
if (!(/^([a-z0-9])([\\w\\.\\-\\+])+([a-z0-9]?)+([a-z]{2,4})\$/i.test(val))) {
//alert( "Please enter a valid web address." );
document.getElementById("urlerr").innerHTML ="Please enter a valid web address, without the http:// and without the www.";
document.getElementById("myForm").web_url.value= ""; // clear the field
setTimeout("document.getElementById('myForm').web_url.focus()", 25); // refocus on it
return false;
}
else {
document.getElementById("urlerr").innerHTML ="";
}
bazz
i am running a form where the url is to be entered. I want to clear out the http:// and the www., which if done, would then show the remainder of the url in the textbox.
I can seem to recall how to wrap the unwanted set of characters into the script.
what have I forgotten?
//check the web_url
var val = document.getElementById("myForm").web_url.value;
val = val.replace(/^\\s+|\\s+\$/g,""); // strip all leading and trailing spaces
val = val.replace(/\\s{2,}/g," "); // convert multiple spaces into a single space
val = val.replace (/[^a-z\\s\\-\.]/gi,""); // strip the characters from the url that are not allowed
val = val.replace (/http/gi, "") // strip the http
val = val.replace (/www./gi, "") // strip the www.
document.getElementById("myForm").web_url.value = val; // write it back to the field
if (!(/^([a-z0-9])([\\w\\.\\-\\+])+([a-z0-9]?)+([a-z]{2,4})\$/i.test(val))) {
//alert( "Please enter a valid web address." );
document.getElementById("urlerr").innerHTML ="Please enter a valid web address, without the http:// and without the www.";
document.getElementById("myForm").web_url.value= ""; // clear the field
setTimeout("document.getElementById('myForm').web_url.focus()", 25); // refocus on it
return false;
}
else {
document.getElementById("urlerr").innerHTML ="";
}
bazz