-1

I'm trying to match unicode regular expression but somehow the \p{L} wont work.

<script>
    var input="teëst";
    var re = /^[a-zA-Z-. \pL]{2,32}$/;
    var is_valid=input.match(re);
    if(is_valid){
        document.write('Regularexpression valid');
    } else {
        document.write('Regularexpression invalid');
    }
</script>

Plnkr.co:

https://plnkr.co/edit/3PCMxqCnwsyrueYQbB8q?p=preview

What am I doing wrong?

UPDATE

https://stackoverflow.com/a/280762/989121

Workaround:

    var re = /^[a-zA-Z- \u00c0-\u017e]{2,32}$/;
Community
  • 1
  • 1
RvdM
  • 95
  • 1
  • 7
  • 1
    It's not you, it's ECMA that does it wrong ;) Js regexes don't support unicode properties. – georg Feb 25 '16 at 09:39
  • 2
    See also http://stackoverflow.com/a/280762/989121 and http://kourge.net/projects/regexp-unicode-block – georg Feb 25 '16 at 09:41
  • My google search on javascript online regular expression check brought me to https://regex101.com/ and this validated my regexp so I thought I was doing something wrong. I would expect such a problem in 1984 but not in 2016. However; Thanks @georg for taking the time to make me aware of this. – RvdM Feb 25 '16 at 09:59

3 Answers3

0

My google search on javascript online regular expression check brought me to regex101.com and this validated my regexp so during the creation of this question I thought I was doing something wrong elsewhere in the code. Points out unicode is not supported yet.

https://stackoverflow.com/a/280762/989121

Workaround:

    var re = /^[a-zA-Z- \u00c0-\u017e]{2,32}$/;
Community
  • 1
  • 1
RvdM
  • 95
  • 1
  • 7
-1

You can use:

var re = /^[a-zA-Z\u00C0-\u017F-. \pL]{2,32}$/;

It uses unicode matching, See here

Marc Duboc
  • 134
  • 1
  • 4
-1

Try with this regular expression:

var re = /[^\x00-\x7F]+/;
MJar
  • 741
  • 9
  • 26
Hary
  • 1
  • 2