-3

For example:

Accept:

  • text
  • Text

Don't accept:

  • text1
  • text@
  • 123@#
  • Te12$
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
Tamil.S
  • 403
  • 3
  • 14
  • 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
  • 88,409
  • 26
  • 156
  • 177