Is this code possible?
switch (rule)
{
case 'email' || 'valid_email':
valid = this.validate_email(field);
break;
}
Is this code possible?
switch (rule)
{
case 'email' || 'valid_email':
valid = this.validate_email(field);
break;
}
No, it is not possible, Switch statements doesn't do arithmetic calculus.
However, you can use case chaining or a bunch of if's:
switch (rule)
{
case 'email':
case 'valid_email':
valid = this.validate_email(field);
break;
}
Close, but this will work:
switch (rule)
{
case 'email':
case 'valid_email':
valid = this.validate_email(field);
break;
}
The reason why it works is that without a break;
, execution continues within the switch
block.