Possible Dup开发者_C百科licate:
Form that removes WWW. and prints result on input?
I'm using this code to remove WWW. from what the user types on an input box, however it works removing the first 4 characters so it doesn't work if the user submits http://www.example.com or http://example.com.
How do I look for the strings "www." and "http://" and remove them from input?
<input type="text" id="url" />
<input type="button" id="submit" value="Go!" />
<div id="output"></div>
<script>
$("#submit").click(
function() {
var url = $("#url").val();
if(url.match(/^www\./))
{
url = url.substring(4);
}
$("#output").html(url);
}
);
</script>
thanks
Don't know if you'll consider it too heavy for what you're trying to do, but a quick google search for "Javascript Uri library" brings me to parseUri 1.2. It is basicly a regex capable of parsing the following:
source protocol authority userInfo user password host port relative path directory file query anchor
精彩评论