I’m trying to apply input validation to a form field by defining a string as follows:
if (value === 'TEXT')
This works, but I need to add some wild card alphanumerics at the end of the input as follows:
if (value === 'TEXT@@@@')
or
if (value === 'TEXT####')
Can anyone tell me what wild card figure should I be using?
1 Like
You might want to try functions like startsWith, endsWith, or includes for a case like this.
Hi Anthony, Thanks for the advice. Trouble is I’m completely new to coding. I’m trying to ensure an input contains te letters “test” I tried entering the following code to my input field and now I’m getting an unexpected “Else” message.
$w('#input1').onCustomValidation((value, reject) => {
console.log(JSON.stringify($w('#input1').validity));
if (value.includes) 'test'
{
console.log('You entered a word containing test');
}
else
{
reject('You did not enter a valid word');
}
});
No worries. There’s a syntax error at the start of the if statement. The code should look like:
$w('#input1').onCustomValidation((value, reject) => {
console.log(JSON.stringify($w('#input1').validity));
if (value.includes('test')) // fixed this line
{
console.log('You entered a word containing test');
}
else
{
reject('You did not enter a valid word');
}
});
Also small note, this line console.log(JSON.stringify($w('#input1').validity));
will only report the validity prior to your custom validation logic because it’s executing before your custom validation logic is evaluated.