Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Alphanumeric String test 2
(version: 0)
Check if a string only contains alpha-numeric characters.
Comparing performance of:
Regex vs charCodeAt
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
var string = "isAlphaNumekjasdnfkjnasdkjfndskajnfkjasdnfkjnasdfkljnaskjdfnkasjdnfkjasndfkjnasdfkjnric091";
Script Preparation code:
var string = "is!AlphaNumekjasdnfkjnasdkjfndskajnfkjasdnfkjnasdfkljnaskjdfnkasjdnfkjasndfkjnasdfkjnric091";
Tests:
Regex
/^[a-z0-9]+$/i.test(string)
charCodeAt
function isAlphaNumeric(str) { for (let i = 0; i < str.length; i++) { let code = str.charCodeAt(i) if (!(code > 47 && code < 58) && // numeric (0-9) !(code > 64 && code < 91) && // upper alpha (A-Z) !(code > 96 && code < 123)) { // lower alpha (a-z) return false } } return true } isAlphaNumeric(string)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Regex
charCodeAt
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Alphanumeric
Alphanumeric String
alpha-numeric string
Alphanumeric String test 1
regex vs js - not Alphanumeric String
Comments
Confirm delete:
Do you really want to delete benchmark?