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