我试图让javascript用户名验证regex。
' ^(?=.{4,16}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$
' └─────┬────┘└───┬──┘└─────┬─────┘└─────┬─────┘ └───┬───┘
' │ │ │ │ no _ or . at the end
' │ │ │ │
' │ │ │ allowed characters
' │ │ │
' │ │ no __ or _. or ._ or .. inside
' │ │
' │ no _ or . at the beginning
' │
' username is 4-16 characters long当我在钛应用程序上使用它时,我得到了这个错误
[ERROR] : Error generating AST for "***register.js"
[ERROR] : Invalid regular expression: /^(?=.{4,16}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/: Invalid group
[ERROR] : Alloy compiler failed我的代码:
var regex = /^(?=.{4,16}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/;
if ( !regex.test(e.value))
{
inputs.Username.borderColor = 'red';
inputs.Username.backgroundColor = '#edcaca';
return false;
}知道为什么它的错误无效组吗?
发布于 2016-06-09 18:57:54
这可能对你有用:
/^(?=.{4,16}$)(?![_.])(?!.*[_.]{2})[a-z0-9._]+[a-z0-9]$/i或者避开大多数的看头:
/^(?!.*[_.]{2})[a-z0-9][a-z0-9._]{2,14}[a-z0-9]$/i问题是,查找后(正(?<=...)和负(?<!...))不支持JavaScript。
发布于 2016-06-09 18:56:08
JavaScript的regex引擎不支持回头看:(?<![_.])。
https://stackoverflow.com/questions/37734009
复制相似问题