1

I'm trying to check if a given UTF-8 string consists of letters only.
I tried the solution I found here: Validating user's UTF-8 name in Javascript

Given string: Ciesiołkiewicz
is tested with var XRegExp = require('xregexp').XRegExp('^\\p{L}+$');

And it's not working because of "ł" letter
I tried XRegExp('^[\\p{Latin}\\p{Common}]+$');
but it's too much, it accepts polish letters but also characters like "$" etc

How can I validate it against letters only? I don't want to type them into regexp manually.

Community
  • 1
  • 1
Xander
  • 1,114
  • 2
  • 9
  • 18

2 Answers2

0
var XRegExp = require('xregexp').XRegExp;
var re = new XRegExp('^\\p{L}+$');

console.log(re.test('Ciesiołkiewicz'));
console.log(re.test('1Ciesiołkiewicz2'));
console.log(re.test('привет'));
console.log(re.test('пр1вет'));

> true
> false
> true
> false

works perfectly.

o_nix
  • 1,146
  • 1
  • 16
  • 30
-2

how about a character range like [a-Z]? thats what i usually use if im looking only for letters

osirisgothra
  • 2,163
  • 24
  • 19