我从一个JSON从服务器正则表达式问题
regexval = ^[A-Za-z\\'\\s\\.\\-\\,]{1,50}$
得到以下的正则表达式有一个与此正则表达式的问题它有一个',这是打破我的js代码来测试这个正则表达式。我如何使这是一个有效的正则表达式?
IM做这样的事情来测试它
if(!regexval.replace(/\\/g,"\\").test(inputVal)) {
}
编辑
以下是JSON
[
{
"ExtensionData": {},
"Data1": null,
"DisplayName": "First Name",
"IsRequired": true,
"LengthValidation": 0,
"Name": "ServiceFirstName",
"RegexValidation": "^[A-Za-z\\'\\s\\.\\-\\,]{1,50}$",
"Type": "String",
"ValidationMessage": "The field 'First Name' doesn't meet the format requirements"
},
{
"ExtensionData": {},
"Data1": null,
"DisplayName": "Last Name",
"IsRequired": true,
"LengthValidation": 0,
"Name": "ServiceLastName",
"RegexValidation": "^[A-Za-z\\'\\s\\.\\-\\,]{1,50}$",
"Type": "String",
"ValidationMessage": "The field 'Last Name' doesn't meet the format requirements"
}
]
在那里做\\只会导致你的正则表达式寻找文字反斜杠(多次)和文字'''','s', .','-'和',' –
那么我如何使正则表达式有效?因为!regexval.test(inputVal)不起作用 – Kishore
是json传递字符串格式的对象吗? –