How I can check that my variable match with this pattern A|0, B|0, C| ... Z|0 in jQuery?
The pattern is [one letter]|0
if (myVar.indexOf((/^[A-Z]+$/+'|0') > -1){
// true;
}
How I can check that my variable match with this pattern A|0, B|0, C| ... Z|0 in jQuery?
The pattern is [one letter]|0
if (myVar.indexOf((/^[A-Z]+$/+'|0') > -1){
// true;
}
Given that input your regex should look like this: /^[A-Z]\|0$/. [A-Z] matches the first uppercase character, then the pipe is escaped using \| before looking for the final 0 at the end of the input string. From there you can use test() to check whether the input meets that expression.
['A|0', 'A0', 'B|0', '0|C', 'd|0'].forEach(item => {
var result = /^[A-Z]\|0$/.test(item);
console.log(item, result);
})