avoid to escape a special characters in javascript

后端 未结 5 1542
你的背包
你的背包 2020-12-01 20:01

My server returns value as support\\testing. When I get this value in client it can be escaped as support testing. \\t is escaped

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 20:40

    Best Solution for this

    function valid(f) {            
            debugger;
            var s = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~";
            str = f.value;
            for (var i = 0; i < str.length; i++) {
               if (s.indexOf(str.charAt(i)) != -1) {
                  //alert("The box has special characters. \nThese are not allowed.\n");
                  f.value = f.value.replace(str.charAt(i), '');// : null;
                  return false;
                }
            }
     }
    

提交回复
热议问题