Sample code that detects if an input character contains an illegal character

  • 2020-03-30 01:41:08
  • OfStack


function checks(t){
   szMsg="[#_%&'/",;:=!^]";
   alertStr="";
   for(i=1;i<szMsg.length+1;i++){
    if(t.indexOf(szMsg.substring(i-1,i))>-1){
     alertStr=" Do not include illegal characters such as [#_%&'/",;:=!^]";
     break;
    }
   }
   if(alertStr != ""){
    alert(alertStr);
    return false;
   }
   return true;
  }

Related articles: