use javascript to split this string "text[99][text]" -
i have input text field in form have name format: sometext[234][sometext]
something <input type="text" name="user[2][city]" />
i need obtain 'user','2' , 'city' split function.
thank
i guess regular expression fits better here.
var res = document.getelementsbytagname('input')[0].getattribute('name').match(/^(\w+)?\[(\d+)?\]\[(\w+)?\]$/); console.log(res[1]); // === "user" console.log(res[2]); // === "2" console.log(res[3]); // === "city"
Comments
Post a Comment