Created
May 2, 2011 16:18
-
-
Save sholsinger/951859 to your computer and use it in GitHub Desktop.
JavaScript method to convert a string into a reasonable "key" string.
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
if(String.prototype.toKey === undefined) | |
{ | |
String.prototype.toKey = function(){ | |
var s = this.toLowerCase(); | |
s = s.replace(/^[0-9_-]+|[^a-z0-9_\s-]|(\s.\s){1,}|[\s]{2,}|[_\s-]+$/ig, ''); | |
s = s.replace(/[\-\s_]+/ig,"_"); | |
return s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment