在JavaScript regexp中使用\p{L}进行验证
当我将其作为验证时,它会为我输入的所有值抛出错误消息。因此,我需要对我认为可以解决其余问题的模式进行一些解释。改变在JavaScript regexp中使用\p{L}进行验证,javascript,regex,Javascript,Regex,当我将其作为验证时,它会为我输入的所有值抛出错误消息。因此,我需要对我认为可以解决其余问题的模式进行一些解释。改变 **var pattern = /^[\p{L}0-9 @#'!&(),\[\].+/-]{1,100}$/;** \\first of all I din understand this pattern. someone plz explain it to me\\ if (!pattern.test(Name)) { alert
**var pattern = /^[\p{L}0-9 @#'!&(),\[\].+/-]{1,100}$/;** \\first of all I din understand this pattern. someone plz explain it to me\\
if (!pattern.test(Name))
{
alert('Account Name must not contain the given values');
Xrm.Page.getAttribute("name").setValue("");
return false;
}
else
{
return true;
}
到
因为您已经将斜杠定义为分隔符,所以必须对斜杠进行转义
正则表达式的含义是,整个字符串必须介于所列字符、数字和字母的1到100个字符之间。在Javascript中,序列
\p{L}
(在字符类中)没有特殊含义;它只是指字母p
或字母{
或字符L
或字符}
。您可能会对另一个库或另一种语言(如PHP、.NET等)的regexps实现感到困惑,它们支持所谓的Unicode字符类别。p{L}和[a-zA-z]是相同的吗?我读到p{L}是Unicode,java不接受Unicode。如果两者都是相同的,那么实际上,当正斜杠是字符类的一部分时,不需要对其进行转义。这不是OP的问题,我想你指的是javascript而不是java。p{L}表示某种形式的“字母”。只有当您只有ASCII字符时,它才与[a-zA-Z]相同。在JavaScript中(至少现在)无法使用\p{L}
。谢谢大家!!请检查,有$re
模式,您可以删除字符类中的第一个#
和0-9A-Za-z
,以匹配除星体码点以外的所有Unicode字母。
/^[\p{L}0-9 @#'!&(),\[\].+/-]{1,100}$/
/^[\p{L}0-9 @#'!&(),\[\].+\/-]{1,100}$/
^^