From 4e22f9cb9aba30cafd1ab59f1bc2a0751dbbc683 Mon Sep 17 00:00:00 2001 From: Sujit Singh Date: Thu, 24 Dec 2020 13:20:27 +0530 Subject: [PATCH] Added snippet for isAlphabetOnly --- snippets/isAlphabetOnly.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 snippets/isAlphabetOnly.md diff --git a/snippets/isAlphabetOnly.md b/snippets/isAlphabetOnly.md new file mode 100644 index 000000000..3ce1dfbbc --- /dev/null +++ b/snippets/isAlphabetOnly.md @@ -0,0 +1,18 @@ +--- +title: isAlphabetOnly +tags: string,regexp,beginner +--- + +Checks if a string contains only alphabetic characters. +- Use `RegExp.prototype.test()` to check if the input string matches against the alphabetic regexp pattern. + + +```js +const isAlphabetOnly = input => /^[a-zA-Z]*$/.test(input) +``` + +```js +isAlphabetOnly('sampleInput'); // true +isAlphabetOnly('this Will fail'); // false +isAlphabetOnly('123'); // false +```