the text box is part of my form. The user has to write a little text, and I want to check this text. I am currently using the following regex:
/^[0-9a-zA-ZäöüÄÖÜ_\-']+$/
Although I mentioned äöüÄÖÜ in regular expression, it treats all words with äöü .. as invalid. In addition, he does not accept empty spaces.
Any ideas on improving regex?
Use a regex that supports Unicode:
/[\pL\pN_\-]+/
the PCRE u modifier allows utf-8 to be used. You also lack space from the regex, and you can condensate it a bit:
/^[0-9a-zäöü\- ]+$/ui
, "i" .
.
-, , äöüÄÖÜ . PHP, , , . , , . , , , .
-, ,
/^[0-9a-z A-ZäöüÄÖÜ_\-']+$/ // note space after a-z
. , . \w , a-zA-ZäöüÄÖÜ
\w
a-zA-ZäöüÄÖÜ
You can simply use \wto indicate all the characters of the word (letters, numbers, etc.). Thus, the regular expression will be equal. /^[\w_\-' ]+$/What text do you think is "valid" in the user?
/^[\w_\-' ]+$/
Source: https://habr.com/ru/post/1777298/More articles:How to install a Linux / Mac computer clock with C # / Mono? - c #Deploying an application developed using C ++ - c ++Inner work more / less than - cjava date time compare two - javaIgnore branches in working copy of SVN - branchPHP system ("cd \"); does not work - directorySearched question - c #How to install Google Map Api on a new Android device? - android')' Expected (java) - javaWhy is viewDidAppear in a UITabBarController executed before a view? - iphoneAll Articles