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

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -