Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for description form input

a textarea is a part of my form. The user has to write a little text and I want to validate this text. For now I am using the following regex:

/^[0-9a-zA-ZäöüÄÖÜ_\-']+$/

Although I have mentioned the äöüÄÖÜ in the regex it handles all words with äöü.. as invalid. Furthermore it does not accept empty spaces.

Any ideas how to improve the regex?

like image 852
UpCat Avatar asked Aug 18 '26 13:08

UpCat


1 Answers

Use a Unicode-aware regex:

/[\pL\pN_\-]+/
like image 50
bcosca Avatar answered Aug 21 '26 03:08

bcosca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!