AppsScriptPulse

String validation for Google Apps Script projects

String validation for Google Apps Script projects

Sourabh Choraria has packaged some of the validator.js methods into a Google Apps Script library. Ported validators currently include isUrl and isEmail, date validators and more. Sourabh has also posted the backstory behind this library.

Source: GitHub – validatorgs/validator.gs: String validation for Google Apps Script projects.

2 comments for “String validation for Google Apps Script projects

  1. Lissa Klein
    2 August, 2021 at 14:2323

    Documentation says “coerce it using input + ”” I am a beginner and Google search did not help explain this.

    • 2 August, 2021 at 19:3323

      Hi Lissa – its a little trick to make sure the value you test is a string (required by the library). Hopefully the code snippet helps explain:

      const input = 8; // input is a number
      input + ''; // value of input is now a string '8'

      There is a blog post here that describes 5 ways in Javascript to convert a value to a string

      If you know your input value is always going to be a string no need to do any additional coding

Leave a Reply

Your email address will not be published. Required fields are marked *