Skip to content

Commit baf4efe

Browse files
chore: add example for a simple regex match on an input (#1087)
Co-authored-by: Simon Boudrias <admin@simonboudrias.com>
1 parent a1da6cf commit baf4efe

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Filter and validate progress example
3+
*/
4+
5+
'use strict';
6+
const inquirer = require('..');
7+
8+
const questions = [
9+
{
10+
type: 'input',
11+
name: 'api_key',
12+
message: 'Please enter a valid API key.',
13+
validate(input) {
14+
if (/([a-f0-9]{40})/g.test(input)) {
15+
return true;
16+
}
17+
18+
throw Error('Please provide a valid API key secret.');
19+
},
20+
},
21+
];
22+
23+
inquirer.prompt(questions).then((answers) => {
24+
console.log(JSON.stringify(answers, null, ' '));
25+
});

0 commit comments

Comments
 (0)