/^[a-z0-9]+$/i

^         Start of string
[a-z0-9]  a or b or c or ... z or 0 or 1 or ... 9
+         one or more times (change to * to allow empty string)
$         end of string    
/i        case-insensitive

Update (supporting universal characters)

if you need to this regexp supports universal character you can find list of unicode characters here.

for example: /^([a-zA-Z0-9\u0600-\u06FF\u0660-\u0669\u06F0-\u06F9 _.-]+)$/

this will support persian.

Answer from Greg on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-validate-an-input-is-alphanumeric-or-not-using-javascript
How to Validate an Input is Alphanumeric or not using JavaScript? - GeeksforGeeks
July 12, 2025 - To validate alphanumeric in JavaScript, regular expressions can be used to check if an input contains only letters and numbers. This ensures that the input is free from special characters. A RegExp is used to validate the input. RegExp is used to check the string of invalid characters that don't contain (a-z) alphabets and all numeric digits to validate. A not operator is used for the desired output. Example...
Discussions

Help me with my regex that only accepts alpha characters, hyphens, and spaces with a minimum of seven characters please
Add a space into the [A-Za-z0-9-] block, like [A-Za-z0-9- ] More on reddit.com
🌐 r/learnprogramming
7
6
November 4, 2022
removing all non-letter characters from a string? ((using regex))
This is very simple with regex. You just need to replace non-words (/\W/ig). So: var string = "lakjsdlkasjdlsaj@£$%^&*klajdlaskjds"; string.replace(/\W/ig, ""); --> "lakjsdlkasjdlsajklajdlaskjds" \w == words, \W == non words. You don't need a loop here as we're using /g which stands for global, so we replace every instance. And just incase I'm using /i as well which ignores the case. As it's regex you can just do /ig and the selectors will stack to ignore case and global. My favorite regex visualiser lives here: https://jex.im/regulex/#!embed=false&flags=ig&re=%5CW More on reddit.com
🌐 r/learnjavascript
10
4
September 28, 2015
Help split a string at all non alphanumeric characters
https://doc.rust-lang.org/std/primitive.str.html#method.split_inclusive It returns an iterator (which is typically what you want, for lazy evaluation), use .collect() to clone the items into a Vec. More on reddit.com
🌐 r/rust
5
4
March 22, 2022
Allow special characters but not spaces?
^[^\s]+$ will match any character(s) that isn't whitespace... since you have the ^ and $ boundaries, it will also make sure your entire line/string matches, so if it starts or ends with a whitespace character ([\r\n\t\f\v ]) it will fail. More on reddit.com
🌐 r/regex
9
3
December 23, 2020
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript regex alphanumeric
Regular Expression for JavaScript to Allow Only Alphanumeric Characters | Delft Stack
October 12, 2023 - This tutorial shows us a Regular Expression (RegEx) that allows only alphanumeric characters using JavaScript. To achieve this, we can use a RegEx expression that matches all the characters except a number or an alphabet in JavaScript.
🌐
LabEx
labex.io › tutorials › string-is-alphanumeric-28407
Checking if a String is Alphanumeric | LabEx
Learn how to use JavaScript and regular expressions to determine if a given string contains only alphanumeric characters.
🌐
IT Explore
itexplore.org › homepage › tips › validating strings as alphanumeric symbols using regex in javascript
Validating Strings as Alphanumeric Symbols Using Regex in JavaScript | IT Explore
May 8, 2025 - To check if a string contains only alphanumeric symbols using regular expressions, use ^[ -~]+$. This regular expression matches strings composed of one or more alphanumeric symbols, such as "Hello, world!".
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-validate-an-input-is-alphanumeric-or-not-using-javascript
How to validate an input is alphanumeric or not using JavaScript?
March 15, 2026 - Regular expressions provide a more concise and efficient way to validate alphanumeric strings. The pattern /^[a-z0-9]+$/i matches strings containing only letters and numbers. let regex = /^[a-z0-9]+$/i; let isAlphanumeric = regex.test(string);
🌐
Plain English
plainenglish.io › home › blog › javascript › check if string is alphanumeric in javascript
Check if string is Alphanumeric in JavaScript
December 31, 2022 - 3. You can also use the String.prototype.search() method to check if a string is alphanumeric. function isAlphanumeric(str) { return str.search(/^[a-zA-Z0-9]+$/) !== -1; } console.log(isAlphanumeric("abc123")); // true console.log(isAlphanumeric("abc!@#")); // false console.log(isAlphanumeric("123456")); // true console.log(isAlphanumeric("")); // false · This method returns the index of the first match, or -1 if the string does not match the pattern. Here is an example of how to use String.prototype.search().
Find elsewhere
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-regexp-exercise-10.php
JavaScript validation with regular expression: Check whether a given value is alpha numeric or not - w3resource
... function is_alphaNumeric(str) { regexp = /^[A-Za-z0-9]+$/; if (regexp.test(str)) { return true; } else { return false; } } console.log(is_alphaNumeric("37828sad")); console.log(is_alphaNumeric("3243#$sew"));
🌐
IT Explore
itexplore.org › homepage › tips › validating strings as alphanumeric using regex in javascript
Validating Strings as Alphanumeric Using Regex in JavaScript | IT Explore
April 27, 2025 - Validating Strings as Alphanumeric ... use ^[a-zA-Z0-9]+$. This regular expression matches strings composed of one or more alphanumeric characters, such as "3DModel". If you want to specify a fixed length of alphanumeric characters, use ^[a-zA-Z0-9]{n}$. For example, to match exactly 6 characters, use ^[a-zA-Z0-9]{6}$. Similarly, ...
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › string › string is alpha or alphanumeric
Check if a JavaScript string contains only alpha or alphanumeric characters - 30 seconds of code
March 24, 2024 - const isAlphaNumeric = str => /^[a-z0-9]*$/gi.test(str); isAlphaNumeric('hello123'); // true isAlphaNumeric('123'); // true isAlphaNumeric('hello 123'); // false (space character is not alphanumeric) isAlphaNumeric('#$hello'); // false ...
🌐
xjavascript
xjavascript.com › blog › regex-for-javascript-to-allow-only-alphanumeric
How to Create a JavaScript RegEx to Allow Only Alphanumeric Characters (No Need for Both Letters and Numbers) — xjavascript.com
For example, "abc" (only letters), "123" (only numbers), and "Abc123" (both) are all valid, while "abc!" or "12 3" are invalid. By the end of this blog, you’ll understand how to construct, test, and refine a JavaScript regex for this specific ...
🌐
javaspring
javaspring.net › blog › regex-to-accept-alphanumeric-and-some-special-character-in-javascript
How to Modify JavaScript Regex to Allow Alphanumeric and Specific Special Characters (-_@./#&+) — javaspring.net
RegExp Object: Created with new RegExp("pattern", "flags"), useful for dynamic patterns. ... For validation, we rarely use g (we want to check the entire input), but i (case-insensitive) is often helpful. ... Uppercase letters (A-Z), lowercase letters (a-z), and digits (0-9). ... JavaScript provides a shorthand for [A-Za-z0-9_]: the \w metacharacter. Thus: ... This matches alphanumerics and underscores (_).
🌐
RegExr
regexr.com › 3a8p3
RegExr: alphanumeric, underscore and .
Supports JavaScript & PHP/PCRE RegEx. Results update in real-time as you type. Roll over a match or expression for details. Validate patterns with suites of Tests. Save & share expressions with others. Use Tools to explore your results. Full RegEx Reference with help & examples.
🌐
W3Resource
w3resource.com › javascript › form › letters-numbers-field.php
JavaScript : Checking for Numbers and Letters - w3resource
November 14, 2023 - Javascript function to check if ... alphanumeric(inputtxt) { var letterNumber = /^[0-9a-zA-Z]+$/; if((inputtxt.value.match(letterNumber)) { return true; } else { alert("message"); return false; } } To get a string contains only ...
🌐
CodingTechRoom
codingtechroom.com › question › create-regex-accept-alphanumeric-characters
How to Create a Regular Expression to Accept Only Alphanumeric Characters - CodingTechRoom
... // Example in JavaScript const alphanumericRegex = /^[a-zA-Z0-9]*$/; const testString1 = "Hello123"; const testString2 = "Hello_123"; console.log(alphanumericRegex.test(testString1)); // true console.log(alphanumericRegex.test(testString2)); ...
🌐
Regex Tester
regextester.com › 97220
only alphanumeric - Regex Tester/Debugger
Regex Tester is a tool to learn, build, & test Regular Expressions (RegEx / RegExp). Results update in real-time as you type. Roll over a match or expression for details. Save & share expressions with others. Explore the Library for help & examples.
🌐
DEV Community
dev.to › tillsanders › let-s-stop-using-a-za-z-4a0m
Let's stop using [a-zA-Z]+ - DEV Community
March 9, 2021 - const regex = /^[\p{Letter}\p{Mark}]+$/u regex.test(burmese) // true regex.test(town) // true ... Till Sanders – Designer and Web Developer from the cloudy mountains of Lüden­scheid. Spent the last decade learning about and shaping the difficult interaction between human and metal minds. ... Currently interested in TypeScript, Vue, Kotlin and Python. Looking forward to learning DevOps, though. ... A while ago, I also learnt that JavaScript regex has unicode support (via /.../u).
🌐
TutorialsPoint
tutorialspoint.com › home › javascript_regexp › javascript regexp: alphanumeric literals
JavaScript RegExp: Alphanumeric Literals
February 13, 2026 - Learn how to use alphanumeric literals in JavaScript regular expressions to match specific characters and patterns effectively.
🌐
regex101
regex101.com › library › hI9cR2
regex101: Alphanumeric and Spaces
Number Length: The phone number must have exactly 8 digits following the operator code, for a total of 11 digits (including the country code and operator code). This regex is commonly used to ensure that the input phone numbers follow the standard ...