Created
June 16, 2019 07:22
-
-
Save craigiswayne/9bee484714264d0ffd00dc6f4336d277 to your computer and use it in GitHub Desktop.
InquirerJS with URL required Input and Validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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