【发布时间】:2016-06-09 18:52:25
【问题描述】:
我正在尝试让 javascript 用户名验证正则表达式
' ^(?=.{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
当我在 Titanium Appcelerator 上使用它时出现此错误
[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;
}
知道为什么它给出错误无效组吗?
【问题讨论】:
标签: javascript appcelerator-titanium