Created
March 20, 2013 11:38
-
-
Save adamcbrewer/5204018 to your computer and use it in GitHub Desktop.
JS: Strip protocols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Strips protocols off strings. | |
* Usefull for ensuring a consistent base where user input is involved. | |
* | |
* Matches: | |
* http:// | |
* https:// | |
* ftp:// | |
* mailto: | |
* www. | |
* @ | |
* | |
* @author Adam Brewer - @adamcbrewer - adamcbrewer.com | |
* | |
* Usage: "http://test.com".stripProtocol(); | |
* | |
*/ | |
String.prototype.stripProtocol = function () { | |
return this.replace(/(www\.|@|mailto\:|(ht|f)tp(s?)\:\/\/)/gm, ''); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment