How to check if a string is single alphabetic characters in JavaScript

1 Answer

0 votes
function isAlphabetic(str) {
  	return /^[a-zA-Z()]$/.test(str);
}

console.log(isAlphabetic("j")); 
console.log(isAlphabetic("ja")); 
console.log(isAlphabetic("j ")); 
  
  
    
    
/*
run:

true
false
false
    
*/

 



answered Sep 18, 2021 by avibootz
...