News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Leonid Mamchenkov's Blog:
PHP regular expression to match English/Latin characters only
August 18, 2011 @ 12:11:44

Leonid Mamchenkov has a quick new post to his blog sharing a regular expression that can be used to check that a string contains only English or Latin characters (no Unicode allowed).

Today at work I came across a task which turned out to be much easier and simpler than I originally thought it would. We have have a site with some user registration forms. The site is translated into a number of languages, but due to the regulatory procedures, we have to force users to input their registration details in English only. Using Latin characters, numbers, and punctuation.

Thankfully the PCRE regular expression engine bundled with PHP makes it simple - it uses a standard regular expression without anything special to accommodate for Unicode characters. He notes that adding the "/u" modifier to the expression makes it "totally malfunction" (where strings are treated as UTF-8). If you'd like an example of some of the tricks that go into supporting Unicode in a regex, see this comment in the PHP manual.

0 comments voice your opinion now!
regular expression example english latin unicode


blog comments powered by Disqus

Similar Posts

Halls of Valhalla: From PHP 5 to 7

Hiveminds Magazine: PHP: What to Do When Your Web Host Turns Off Fopen

PHPF1.com: PHP Form Tutorial

Jan Lehnardt's Blog: Using the Zend Framework with Code Igniter (an alternative)

Ken Guest's Blog: Validation in Depth - a retort to using just regular expressions


Community Events

Don't see your event here?
Let us know!


voicesoftheelephpant framework interview podcast unittest library xdebug series language introduction install api opinion example release extension laravel5 php7 community laravel

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework