Files
30-seconds-of-code/snippets/isAlpha.md
Isabelle Viktoria Maciohsek 8bf67754ce Make expertise a field
2022-03-01 20:21:45 +02:00

22 lines
471 B
Markdown

---
title: String is alpha
tags: string,regexp
expertise: beginner
firstSeen: 2020-12-31T14:01:42+02:00
lastUpdated: 2020-12-31T14:01:42+02:00
---
Checks if a string contains only alpha characters.
- Use `RegExp.prototype.test()` to check if the given string matches against the alphabetic regexp pattern.
```js
const isAlpha = str => /^[a-zA-Z]*$/.test(str);
```
```js
isAlpha('sampleInput'); // true
isAlpha('this Will fail'); // false
isAlpha('123'); // false
```