I have the following function that i am using to check fields on a form for invalid characters (mostly foreign language characters). It works if the input string is all invalid characters (i.e. 日本語?, and if there are VALID characters before the invalid ones (i.e. ABC日本語?, but not if there are valid characters before AND after the invalid ones. Can anyone tell me what i’m doing wrong? Thanks!
function chkchar2()
{
for (var j=0;j < document.forms[0].length;j++)
{
if (document.forms[0].elements[j].type == “text” || document.forms[0].elements[j].type == “textarea”)
{
for (var i = 0; i < document.forms[0].elements[j].value.length; i++)
{
var myregexp = new RegExp(“[A-Z]|[a-z]|\s|[_]|[0-9]|[.]|[‘]|[“]|[!]|[@]|[#]|[$]|[%]|[&]|[*]|[(]|[)]|[-]|[=]|[+]|[~]|[;]|[:]|[<]|[>]|[.]|[?]|[/]|[|]|[\]|[{]|[}]|[\^]”);
for (var x = 0; x < document.forms[0].elements[j].value.length; x++)
{
var match = myregexp.exec(document.forms[0].elements[j].value.substring(x));
if (match != null) {
} else {alert(“invalid”);
j++;
}
}
}
}
}
}