I am stuck on preg_match
vs regex
I am trying to verify user input value on client side. For their first and last name i have this expression that is good for preg_match
;
~^([\p{L}-\s']+)$~ui <--- working fine with preg_match
I need the équivalent for JavaScript Regex
I have a lot of hard time figuring it out and nothing works.
Ex;
Jean-François d'abigaël passes with ~^([\p{L}-\s']+)$~ui
Preg_match
I need the Regex version of it.
Also would like a version for PHP Preg_match
and JavaScript Regex
that would accept the same thing but with numbers [0-9]
.
EDIT
var re = /~^([\p{L}-\s']+)$~/i; <----- Not working at all
if (re.test(value) == true){
// it passes regex
}
else{
// it does not
}
String example ;
- à_wéird_Us0r-Nam3 <--- Unicode with A-Z àéçûö.... 0-9 -_’' Regex + Pregmatch
- Étiène Boîs d'autêgne <--- Same but no _ or numbers for Regex
Help would be much appreciated.
Since your
\u00C0-\u017F
range is not really matching all the letters, you can use the following regex solution that is using the Unicode ranges (taken and modified a bit from XRegExp Unicode categories):NOTE: Starting with ECMAScript 2018, JavaScript
RegExp
supports Unicode property escapes, provided you use/u
modifier:This was clearly not a duplicate!
Found this here that helped.
I found the solution;
This line will only accept diacritics, letters, numbers, space, -,',’ Wich was exactly what i needed.
I just have to remove the numbers and it will be good for my names as well.