-1

Write a title validation function - validateTitle, which takes an argument and validates it by the rules:

  • Title length must be less than 2 characters but less than 20.

  • Title must start with an uppercase letter

  • Function should return ‘VALID’ if the string meets the requirements or ‘INVALID’ if it does not. And return 'Incorrect input data' if the given argument not a string. Do not use regular expressions. My solution is not full

      const validateTitle = (value) => {
      if (typeof value !== "string") {
        return "Incorrect input data";
      }
      for (let i = 2; i <= 19; i++) {}
    };
    

    Examples: validateTitle(false) // 'Incorrect input data' validateTitle([]) // 'Incorrect input data' validateTitle('s') // 'INVALID validateTitle('12title') // 'INVALID' validateTitle('Title!') // 'VALID' validateTitle('Title?') // 'VALID'

1 Answers1

0
function validTitle(tempString){
 let validFlag = ((tempString.charAt(0) == tempString.charAt(0).toUpperCase()) && 
                 (tempString.length > 2 && tempString.length < 20 )) ? true : false;
  return validFlag ? 'VALID' : 'INVALID'
}

try this -

Toxy
  • 696
  • 5
  • 9
  • I have edited it. (GREATER THAN SYMBOL WAS WRONG AND I MISS A BRACKET ) Now its working – Toxy Apr 09 '21 at 11:08