Skip to content

Instantly share code, notes, and snippets.

@craigiswayne
Created June 16, 2019 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigiswayne/9bee484714264d0ffd00dc6f4336d277 to your computer and use it in GitHub Desktop.
Save craigiswayne/9bee484714264d0ffd00dc6f4336d277 to your computer and use it in GitHub Desktop.
InquirerJS with URL required Input and Validation
'use strict';
var inquirer = require('inquirer');
var questions = [
{
type: 'input',
name: 'url',
message: 'Enter in a URL',
required: true,
validate: function(value) {
var pass = value.match(/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}$|^$/i);
if (!pass || !value) {
return 'Please enter a valid url';
}
return true;
}
}
];
inquirer.prompt(questions).then(answers => {
console.log("Answers",answers);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment