check alphabet in javascript code example
Example 1: javascript number in alphabet
function numToSSColumn(num){
let s = '', t;
while (num > 0) {
t = (num - 1) % 26;
s = String.fromCharCode(65 + t) + s;
num = (num - t)/26 | 0;
}
return s || undefined;
}
numToSSColumn(0);
numToSSColumn(1);
numToSSColumn(26);
numToSSColumn(-1);
numToSSColumn(27);
numToSSColumn(475254);
Example 2: checking if a character is an alphabet in js
function isLetter(str) {
return str.length === 1 && str.match(/[a-z]/i);
}
Example 3: how to check if a string is alphabetic in javascript
function isAlphaOrParen(str) {
return /^[a-zA-Z()]+$/.test(str);
}