Nikola
Nikola

Reputation: 31

How can i validate jquery Regular expression?

const input = [
  {q: "58b988ff62279282090dd314"}, 
  {q: "58b988ff62279282090dc152"},
  {q: "58b988ff62279282090dbf09"}
];

input.forEach(({q}) => $(`[data-id="${q}"]`).css("background", "lime"));

How can i validate on (q) value Regular expression ?

I want use regex code in this way because my value it's always changing.

Meanwhile I am using that code on Greasemonkey.

{q: "5..........................bf09"} 

Upvotes: 0

Views: 53

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520888

It appears that you want to apply a regex which checks that the q value starts with 5 and ends with bf09. I don't know how to phrase this without using an explicit anonymous function:

input.forEach(function(element) {
    if (element.match(/^5.{19}bf09$/)) {
        $(`[data-id="${element}"]`).css("background", "lime"));
    }
})

Upvotes: 1

Related Questions