I have one string and i need to pass every character of that string for multiples conditions...
what i want
if one character of that string fulfills one of the multiple conditions don't evaluate this condition for the next character, but evaluate the remaining conditions for the remaining characters. other thing is i need to know when all conditions have been fulfilled. what is the best form or the most optimal way to do it?
what I've done
I try to pass every element for multiple condition with jquery $.each, I go through all the conditions and step to each condition all the string. this tells me when some element of the string fulfills one of the conditions, but it doesn't tell me when the whole string has fulfilled all the conditions.
// Multiple conditions
const conditions = [
{
isInvalid: function(str) {
return !str.match(/[a-z]/g);
}
},
{
isInvalid: function(str) {
return !str.match(/[A-Z]/g);
}
},
{
isInvalid: function(str) {
return !str.match(/[0-9]/g);
}
},
{
isInvalid: function(str) {
return !str.match(/[\!\@\#\$\%\^\&\*]/g);
}
},
{
isInvalid: function(input) {
return str.length < 8;
}
},
];
const stringToCheck = 'mystring';
$.each( conditions , ( i, condition ) => {
const isInvalid = condition.isInvalid( mystring );
if ( isInvalid ) {
return true
} else {
retur false
}
});