/^[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
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript regex alphanumeric
Regular Expression for JavaScript to Allow Only Alphanumeric Characters | Delft Stack
October 12, 2023 - To remove non-alphanumeric characters from a string, you will first call the replace() method and pass a regular expression (RegEx) that matches all non-alphanumeric characters as the first parameter and an empty string as the second parameter.
Discussions

Quick way to extract alphanumeric characters from a string in Javascript - Stack Overflow
I have a string (with CSS selectors to be precise) and I need to extract only alphanumeric characters from that string. ... Sometimes you cannot be both short and elegant while being quick at the same time. ... View this entry from 2008: "RegEx for JavaScript to allow only alphanumeric". More on stackoverflow.com
🌐 stackoverflow.com
jquery - Allowing only Alphanumeric values - Stack Overflow
Possible Duplicate: How to prevent users from entering invalid characters inside an input field I have 3 textboxes on a page. One of them should allows numbers, the other alphabets and the 3rd ... More on stackoverflow.com
🌐 stackoverflow.com
Check for Palindromes: Would a ``` for loop ``` help? Removing non-Alphanumeric Characters in Javascript?
Not sure how to get started on this one. I've heard a for loop is a good idea. More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
19
1
January 11, 2017
javascript - Regex to remove all non alpha-numeric and replace spaces with + - Stack Overflow
I'm looking to use regex to try remove all non alpha-numeric characters from a string and replace spaces with a + All I want to permit is basically alphabetical words A-Z and + This is specifical... More on stackoverflow.com
🌐 stackoverflow.com
August 20, 2015
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-remove-non-alphanumeric-characters-from-a-string
JavaScript Program to Remove Non-Alphanumeric Characters from a String - GeeksforGeeks
July 23, 2025 - In this approach, we convert the input string to an array of characters using Array.from(), then use the filter method to keep only alphanumeric characters.
🌐
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 ... These methods can serve as a great starting point for more complex string validation patterns. You can further customize the regular expressions to suit your specific requirements (e.g. allowing spaces, hyphens, or underscores in the string). ... Learn how to work with whitespaces in JavaScript strings, using these simple yet powerful regular expression techniques.
🌐
Plain English
plainenglish.io › home › blog › javascript › check if string is alphanumeric in javascript
Check if string is Alphanumeric in JavaScript
December 31, 2022 - Here is an example of how you can ... console.log(isAlphanumeric("")); // false · The regular expression /^[a-zA-Z0-9]+$/ tests the string to see if it contains only letters and numbers....
🌐
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.
🌐
Medium
medium.com › luisbajana › allowing-only-alphanumeric-characters-89ff03d9171
Allowing only alphanumeric characters | by Luis Bajaña | luisbajana | Medium
September 18, 2017 - Sometimes you have to include some extreme validations over your text fields, the other day I had this requirement: “Allowing only alphanumeric characters and validate it when the user is typing”, you may say “there are tons of libraries for that purpose out there”, yes, but, what if you just want to validate one field? Include an entire library for that is too much… · [code language=”javascript”] $(‘body’).on(‘keypress’,’.js-only-alpha-numeric’, function (e){ var re = new RegExp(“^[a-zA-Z0–9]+$”, “g”); if(!re.test(String.fromCharCode(e.keyCode))) return false; }); [/code]
🌐
W3Resource
w3resource.com › javascript › form › letters-numbers-field.php
JavaScript : Checking for Numbers and Letters - w3resource
November 14, 2023 - function alphanumeric(inputtxt) { var letters = /^[0-9a-zA-Z]+$/; if(inputtxt.value.match(letters)) { alert('Your registration number have accepted : you can try another'); document.form1.text1.focus(); return true; } else { alert('Please input alphanumeric characters only'); return false; } }
Find elsewhere
🌐
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
Without $, the regex might ignore invalid characters at the end (e.g., "abc123!" would match "abc123"). Final Pattern: ^[a-zA-Z0-9]+$ ensures the entire string consists of one or more alphanumeric characters.
🌐
Regex Tester
regextester.com › 97220
only alphanumeric - Regex Tester/Debugger
Url checker with or without http:// or https:// Match string not containing string Check if a string only contains numbers Only letters and numbers Match elements of a url date format (yyyy-mm-dd) Url Validation Regex | Regular Expression - Taha Match an email address Validate an ip address nginx test Extract String Between Two STRINGS match whole word Match or Validate phone number Match html tag Find Substring within a string that begins and ends with paranthesis Match dates (M/D/YY, M/D/YYY, MM/DD/YY, MM/DD/YYYY) Blocking site with unblocked games Empty String Match if doesn't start with string RegEx for Json
🌐
JavaScript in Plain English
javascript.plainenglish.io › check-if-string-is-alphanumeric-in-javascript-e325caa3ee
Check if the string is Alphanumeric in JavaScript
December 30, 2022 - New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.
🌐
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 the most efficient and readable solution for alphanumeric validation. Use /^[a-z0-9]+$/i for positive matching or /[^a-zA-Z0-9]/ for detecting invalid characters.
🌐
ASPSnippets
aspsnippets.com › Articles › 2118 › Regular-Expression-Regex-to-accept-only-Alphanumeric-Alphabets-and-Numbers-in-TextBox-in-ASPNet
Regular Expression Regex to accept only Alphanumeric Alphabets and Numbers in TextBox in ASPNet
February 1, 2019 - OnClientClick event of the Button, a JavaScript function is executed which validates the TextBox text against the Regular Expression (Regex) and if it contains character other than Alphabets or Numbers then an error message is displayed. ... 3. Regular Expression (Regex) to accept only Alphanumeric (Alphabets and Numbers) in TextBox using jQuery
🌐
GitHub
github.com › stdlib-js › assert-is-alphanumeric
GitHub - stdlib-js/assert-is-alphanumeric: Test whether a string contains only alphanumeric characters. · GitHub
$ echo -n 'beep\t01abc23456789' | is-alphanumeric --split '\t' false true · @stdlib/assert-is-digit-string: test whether a string contains only numeric digits. This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing.
Author   stdlib-js
🌐
Regex Pal
regexpal.com › 97220
only alphanumeric - Regex Pal
Comments PostPosting GuidelinesFormatting · Top Regular Expressions Url checker with or without http:// or https:// Match string not containing string Check if a string only contains numbers Only letters and numbers Match elements of a url date format (yyyy-mm-dd) Url Validation Regex | Regular ...