jquery guid pattern selector

علی ذوالفقار
1402/03/01 07:04:32 (194)
// a ppatern to detect guid 
var ptt = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', 'i');

// select all guid containig fields
var  opts = $("td").filter(function () {
    return ptt.test($(this).text()); 
});

// add a link in the opts (operation boxes)
opts.each( (i,o)=>{    
    $(o).html(`<a href="https://mysite.com/api/posts/${o.innerText}" target="_blank">view post</a>`)
})
Back