Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add example for a simple regex match on an input #1087

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/inquirer/examples/regex-validate-input.js
@@ -0,0 +1,25 @@
/**
* Filter and validate progress example
*/

'use strict';
const inquirer = require('..');

const questions = [
{
type: 'input',
name: 'api_key',
message: 'Please enter a valid API key.',
validate(input) {
if (/([a-f0-9]{40})/g.test(input)) {
return true;
}

throw Error('Please provide a valid API key secret.');
},
},
];

inquirer.prompt(questions).then((answers) => {
console.log(JSON.stringify(answers, null, ' '));
});