在JavaScript regexp中使用p{L}进行验证

validation using p{L} in JavaScript regexp

本文关键字:验证 regexp JavaScript      更新时间:2023-09-26
**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;
        }

当我给出这个作为验证时,它会为我输入的所有值抛出错误消息。所以我需要一些关于模式的解释,我认为这将解决其余的问题。

在Javascript中,序列'p{L}(在字符类中)没有特殊含义;它仅仅意味着字母p或字母{或字符L或字符}。您可能会混淆XRegExp,另一个库,或其他语言(如Perl, PHP, . net等)的regexp实现,它支持所谓的Unicode字符类别。

变化

/^['p{L}0-9 @#'!&(),'['].+/-]{1,100}$/

/^['p{L}0-9 @#'!&(),'['].+'/-]{1,100}$/
                          ^^

,因为您必须转义斜杠/,因为您已经将它们定义为分隔符。

regex的意思是你的整个字符串必须在列出的字符,数字和字母的1到100个字符之间。