我有一个只允许字母、数字、空格或连字符的正则表达式。但是,我想禁止用户执行以下操作:
hello--world Have more than one hyphen sitting next to each other
--hello Have a hyphen in the beginning. It must have a number or letter first
我该如何实现?我当前的正则表达式如下所示:
let alphanumericTest = new RegExp("^\s*([0-9a-zA-Z- ]*)\s*$");
最佳答案
您可以试试这个正则表达式。 ^\s*[0-9a-zA-Z](?:(?!--)[0-9a-zA-Z- ])*$
关于javascript - 正则表达式禁止特定序列中的某些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57369784/