add isAlphaNumeric snippet

This commit is contained in:
sakpal
2020-09-06 14:59:16 +10:00
parent 13e9057337
commit 6e1c82d78b

View File

@ -0,0 +1,19 @@
---
title: isAlphaNumeric
tags: string,regexp,intermediate
---
Checks if a string contains only alphanumeric characters.
Use `String.prototype.match()` to check if input string matches against alphanumeric regex pattern.
```js
const isAlphaNumeric = (str) => !!str.match(/^[a-z0-9]+$/gi);
```
```js
isAlphaNumeric('hello123'); // true
isAlphaNumeric('123'); // true
isAlphaNumeric('hello 123'); // false (space character is not alphanumeric)
isAlphaNumeric('#$hello'); // false
```