Created
October 2, 2012 10:11
-
-
Save martinnormark/3817999 to your computer and use it in GitHub Desktop.
Trim string for array/collection paths
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
// In ASP.NET MVC, input fields are often named e.g. 'Products[5].Name'. | |
// To get rid of the 'Products[5]' part, use the following. | |
inputChanged: function (event) { | |
var regex = new RegExp(/^\w*\[\d\]\./), | |
$input = $(event.target), | |
inputName = $input.attr("name"); | |
while (regex.test(inputName)) { | |
var matches = regex.exec(inputName); | |
inputName = inputName.replace(matches[0], ""); | |
} | |
console.log(inputName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment