RegEx for Javascript to allow only alphanumeric

前端 未结 18 1521
轻奢々
轻奢々 2020-11-22 15:13

I need to find a reg ex that only allows alphanumeric. So far, everyone I try only works if the string is alphanumeric, meaning contains both a letter and a number. I just w

18条回答
  •  生来不讨喜
    2020-11-22 15:20

    Extend the string prototype to use throughout your project

        String.prototype.alphaNumeric = function() {
            return this.replace(/[^a-z0-9]/gi,'');
        }
    

    Usage:

        "I don't know what to say?".alphaNumeric();
        //Idontknowwhattosay
    

提交回复
热议问题