日期:2014-05-16 浏览次数:20382 次
// forbit user to input the charactor "|" function forbitSpecialCharactor(input){ var value = input.value; var spec = "|"; var firstIndex = value.indexOf(spec); var lastIndex = value.lastIndexOf(spec); if(firstIndex == -1){ return true; }else{ // 只有一个"|"时,直接删除该字符 if(firstIndex == lastIndex){ var after = ""; if(value.length - 1 > firstIndex){ after = value.substring(firstIndex + 1, value.length); } input.value=value.substring(0, firstIndex).concat(after); }else{ // 如果copy含多个"|"字符的字符串到控件中,把输入框设为空值 input.value=""; } return false; } }