1

I've got several input boxes like so:

<input type="checkbox" name="checkbox_item[500]" /> <input type="checkbox" name="checkbox_item[10]" /> <input type="checkbox" name="checkbox_item[2]" /> <input type="checkbox" name="checkbox_item[1]" /> <input type="checkbox" name="checkbox_item[]" /> 

So I'm using the following regex pattern checkbox_item\[\d+\] which works nicely in my regex tester but I cannot get it to work with Jquery. This is my Jquery code:

console.log($("input:regex(name, /checkbox_item\[\d+\]/)").length); 

I was expecting 4 but instead got 28!

Can somebody shed any light on this?

Thanks

3
  • 1
    So do you use the following regex filter for jQuery? Commented Oct 2, 2013 at 10:36
  • ... if you do, try to remove slashes / before and after regular expression in the selector, i.e. :regex(name, checkbox_item\[\d+\]). Commented Oct 2, 2013 at 10:41
  • Possible duplicate of stackoverflow.com/questions/19095607/… Commented Oct 2, 2013 at 10:42

3 Answers 3

1

I don’t think jQuery natively supports regular expressions in selectors in that way.

But you could use the Attribute Starts With Selector [name^="value"].

Sign up to request clarification or add additional context in comments.

Comments

1

You can use Attribute Starts with like

console.log($("input[type=checkbox][name^='checkbox_item']").length) 

Demo

Comments

1

I don't know if i understand it corretly, but you want to get the total elements that begins with checkbox_item?

$("input[name^=checkbox_item]").length 

This will give you the total elements that begins with checkbox_item.

more info about this selector here.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.