JavaScript - String Contains Only Alphabetic Characters or Not Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Here are several methods to check if a string contains only alphabetic characters in JavaScriptUsing Regular Expression (/^[A-Za-z]+$/) - Most USedThe most common approach is to use a regular expression to match only alphabetic characters (both uppercase and lowercase). JavaScript let s = "HelloWorld"; let isAlphabetic = /^[A-Za-z]+$/.test(s); console.log(isAlphabetic); OutputtrueThis checks if the string contains only the letters A-Z and a-z. It will return true if all characters are alphabetic and false otherwise.Using every() Method with Regular ExpressionThe every() method can be used with a regular expression to iterate over each character and verify it matches [A-Za-z]. JavaScript let s = "HelloWorld"; let isAlphabetic = Array.from(s).every((char) => /[A-Za-z]/.test(char)); console.log(isAlphabetic); OutputtrueThis approach works well for checking each character individually against the pattern.Using for Loop with charCodeAt()Using a for loop, you can check each character for alphabets without regular expressions. JavaScript let s = "HelloWorld"; let isAlphabetic = true; for (let i = 0; i < s.length; i++) { let code = s.charCodeAt(i); if (!(code >= 65 && code <= 90) && !(code >= 97 && code <= 122)) { isAlphabetic = false; break; } } console.log(isAlphabetic); OutputtrueUsing every() with charCodeAt()This method uses Array.from() to split the string into characters, then checks each one’s ASCII code. JavaScript let s = "HelloWorld"; let isAlphabetic = Array.from(s).every(char => { let code = char.charCodeAt(0); return (code >= 65 && code <= 90) || (code >= 97 && code <= 122); }); console.log(isAlphabetic); OutputtrueUsing isNaN() FunctionTo check if each character is non-numeric, you can use isNaN() along with checking for alphabetic ranges. JavaScript let s = "HelloWorld"; let isAlphabetic = Array.from(s).every( (char) => isNaN(char) && /[A-Za-z]/.test(char) ); console.log(isAlphabetic); OutputtrueUsing filter() with match()The filter() method can filter out non-alphabetic characters by checking each one with match(), and the length of the result should match the original string length if all are alphabetic. JavaScript let s = "HelloWorld"; let isAlphabetic = s.split("").filter((char) => char.match(/[A-Za-z]/)).length === s.length; console.log(isAlphabetic); OutputtrueThe regular expression (/^[A-Za-z]+$/) remains the most efficient approach. However, methods like every() with charCodeAt() or a for loop offer flexibility for character-by-character validation. Comment More infoAdvertise with us Next Article JavaScript Program to Check if a Character is Vowel or Not K kohliami558i Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League javascript-string JavaScript-DSA JavaScript-Program Geeks Premier League 2023 +3 More Similar Reads JavaScript - Check if a String Contains Any Digit Characters Here are the various methods to check if a string contains any digital character1. Using Regular Expressions (RegExp)The most efficient and popular way to check if a string contains digits is by using a regular expression. The pattern \d matches any digit (0-9), and with the test() method, we can ea 4 min read JavaScript Program to Count Number of Alphabets We are going to implement an algorithm by which we can count the number of alphabets present in a given string. A string can consist of numbers, special characters, or alphabets.Examples:Input: Str = "adjfjh23"Output: 6Explanation: Only the last 2 are not alphabets.Input: Str = "n0ji#k$"Output: 4Exp 3 min read JavaScript Program to Check if a Character is Vowel or Not In this article, we will check if the input character is a vowel or not using JavaScript. Vowel characters are âaâ, âeâ, âiâ, âoâ, and âuâ. All other characters are not vowels. Examples: Input : 'u'Output : TrueExplanation: 'u' is among the vowel characters family (a,e,i,o,u).Input : 'b'Output : Fal 4 min read JavaScript - Find if a Character is a Vowel or Consonant Here are the different methods to find if a character is a vowel or consonant1. Using Conditional Statements (If-Else)The most widely used approach is to check the character against vowels (both uppercase and lowercase) using conditional statements (if-else). This method is simple and effective for 5 min read JavaScript Program to Find Missing Characters to Make a String Pangram We have given an input string and we need to find all the characters that are missing from the input string. We have to print all the output in the alphabetic order using JavaScript language. Below we have added the examples for better understanding. Examples: Input : welcome to geeksforgeeksOutput 6 min read JavaScript Program to Check Whether a String Starts and Ends With Certain Characters In this article, We are going to learn how can we check whether a string starts and ends with certain characters. Given a string str and a set of characters, we need to find out whether the string str starts and ends with the given set of characters or not. Examples: Input: str = "abccba", sc = "a", 3 min read Like