-3

For example:

Accept:

  • text
  • Text

Don't accept:

  • text1
  • text@
  • 123@#
  • Te12$
Michał Perłakowski
  • 80,501
  • 25
  • 149
  • 167
Tamil.S
  • 343
  • 1
  • 12
  • have you tried to write a regex to solve this? what does it look like? where is your code? – Dan O Jun 07 '17 at 16:40

1 Answers1

4

Try this:

const isValid = str => /^[a-zA-Z]{2,5}$/.test(str);
console.log(isValid('test')); // true
console.log(isValid('Test')); // true
console.log(isValid('test1')); // false
console.log(isValid('text@')); // false
console.log(isValid('123@#')); // false
console.log(isValid('Te12$')); // false
Michał Perłakowski
  • 80,501
  • 25
  • 149
  • 167