X
X
xSPQRx2020-04-17 19:40:07
JavaScript
xSPQRx, 2020-04-17 19:40:07

How to filter a list by the presence of numbers at the beginning of a string?

I do the list filter on the first characters. The letters are ok, but there is a problem with the numbers.
How to make it so that when you click on the "1" button (see screenshot), only lines that start with a number (from 0 to 9) are displayed.

5e99db07b62dc251449595.png

the code

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-04-17
@xSPQRx

$(document).on('click', '.testa', function() {
  const reg = RegExp(`^[${$(this).text()}]`, 'i');
  $('.red a').hide().filter((i, n) => reg.test($(n).text())).show();
  $(this).addClass('active').siblings().removeClass('active');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question