Best way to alphanumeric check in JavaScript

后端 未结 11 2268
逝去的感伤
逝去的感伤 2020-11-28 05:09

What is the best way to perform an alphanumeric check on an INPUT field in JSP? I have attached my current code



        
11条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 05:26

    In a tight loop, it's probably better to avoid regex and hardcode your characters:

    const CHARS = new Set("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
    function isAlphanumeric(char) {
        return CHARS.has(char);
    }
    

提交回复
热议问题