javascript code to check special characters

后端 未结 6 1765
后悔当初
后悔当初 2020-12-08 10:45

I have JavaScript code to check if special characters are in a string. The code works fine in Firefox, but not in Chrome. In Chrome, even if the string does not contain spec

6条回答
  •  旧巷少年郎
    2020-12-08 11:20

    If you don't want to include any special character, then try this much simple way for checking special characters using RegExp \W Metacharacter.

    var iChars = "~`!#$%^&*+=-[]\\\';,/{}|\":<>?";
    if(!(iChars.match(/\W/g)) == "") {
        alert ("File name has special characters ~`!#$%^&*+=-[]\\\';,/{}|\":<>? \nThese are not allowed\n");
        return false;
    }
    

提交回复
热议问题