basically tring restrict special characters input.
var ichars = "[!@#$%^&*()+=\\-\\[\\]\\\';,./{}|\":<>?\\n]{1}"; if(((document.all.tranrmks.value).search(ichars)) != -1){ alert("speacial characters not allowed in notes"); return false; }
but need check character '\'
.
if(((document.all.tranrmks.value).indexof("\"))>=0){ alert("\ not allowed"); return false; }
but above code not working me..please let me know other way check \
.
as @vohuman has said, backslash escapes next character here closing literal(")
. use \\
instead.
if(((document.all.tranrmks.value).indexof("\\"))>=0){ alert("\\ not allowed"); return false; }
or
you use includes() functions checks existence of string given.
if((document.all.tranrmks.value).includes("\\")){ alert("\\ not allowed"); return false; }
Comments
Post a Comment