0
**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;
        }

when I give this as validation it is throwing error message for all the values I enter. So I need some explanation on the pattern which I think will solve the rest.

  • Please check [my post](http://stackoverflow.com/a/31115742/3832970), there is `$re` pattern where you can remove the first `#` and `0-9A-Za-z` in the character class to match all Unicode letters but astral code points. – Wiktor Stribiżew Jul 16 '15 at 09:58

2 Answers2

-1

In Javascript, the sequence \p{L} (in a character class) has no special meaning; it simply means the letter p or the letter { or the character L or the character }. You're probably getting confused with XRegExp, another library, or another language's (eg Perl, PHP, .NET etc.) implementation of regexps, which support so-called Unicode character categories.

-2

Change

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

to

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

                          ^^

since you have to escape slashes / since you have defined them to be delimiters.

The meaning of the regex is that your entire string has to be between 1 and 100 characters of the listed characters, numbers and letters.

vks
  • 67,027
  • 10
  • 91
  • 124
tomsv
  • 7,207
  • 6
  • 55
  • 88
  • Is p{L} and [a-zA-z] are same? I read that p{L} is a Unicode and java doesn't accept Unicode. If both are same then shall I replace – bhavithra kumar Jul 16 '15 at 09:28
  • Actually, you **do not** need to escape the forward slash when it is part of a character class. So that's not the OP's problem. –  Jul 16 '15 at 09:35
  • 1
    I assume you mean javascript and not java. p{L} means some form of "letter". Only if you have only ASCII characters is it the same as [a-zA-Z]. – tomsv Jul 16 '15 at 09:37
  • 3
    It is not possible to use `\p{L}` in JavaScript (at least now). – Wiktor Stribiżew Jul 16 '15 at 09:38