I use the following function to examine whether an entry contains invalid characters. The regular expression test() function return false when the input string contains excluded character(s). Is there any way to return the first character/character(s) making the test fail?
function isContainInvalidCharacter(str) {
//--- Allowable characters in string a-z, A-Z, 0-9, Space @,.$)/(-%:
if ( /^[A-Za-z0-9p{sc=Hani}s,.@$)/(%:-]+$/u.test(str) == false) {
return true;
} else
return false;
}