PHP and regexp accept only Greek characters in the form

I need a regular expression that only accepts Greek characters and spaces for the name field in my form (PHP). I tried several pins on the net, but no luck. Any help would be appreciated.

+6
source share
5 answers

I am not very accurate in the Greek alphabet, but if you want to do this using the Latin alphabet, you will do the following:

/^[a-zA-Z\s]*$/ 

To do this with Greek, you replace a and z with the first and last letters of the Greek alphabet. If I remember my biblical fragments correctly, these are α and ω . Thus, the code will look like this:

 /^[α-ωΑ-Ī©\s]*$/ 
+4
source

Solution with a full letter with letters with an accent:

 /^[A-Za-zĪ‘-Ωα-Ļ‰ĪÆĻŠĪĻŒĪ¬Ī­ĻĻ‹Ī°Ī®ĻŽ]+$/ 
+16
source

Greek and Coptic in utf-8 appear to be in the range U + 0370 - U + 03FF. Keep in mind: space, - , a . etc. Not....

0
source

Other answers here did not help me. Greek Unicode characters are included in the following two blocks

  • Greek and Coptic U + 0370 to U + 03FF (regular Greek letters)
  • Greek Extended U + 1F00 to U + 1FFF (Greek letters with diacritics)

The following regular expression matches whole Greek words:

 [\u0370-\u03ff\u1f00-\u1fff]+ 

I will allow the reader to translate this into any programming language format that they can use.

0
source

The modern Greek alphabet in UTF-8 is in the U + 0386 - U + 03CE range .

So the regex that only Greek characters need to accept is:

 $regex_gr = '/^[\x{0386}-\x{03CE}]+$/u'; 

or (with spaces)

 $regex_gr_with_spaces = '/^[\x{0386}-\x{03CE}\s]+$/u'; 
-1
source

Source: https://habr.com/ru/post/889881/


All Articles