PHP regular expression to match English/Latin characters only

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.

I’ve refreshed my knowledge of Unicode and PCRE.  And then I came up with the following method which seems to do the job just fine.

/**
 * Check that given string only uses Latin characters, digits, and punctuation
 *
 * @param string $string String to validate
 * @return boolean True if Latin only, false otherwise
 */
public function validateLatin($string) {
    $result = false;

    if (preg_match("/^[\w\d\s.,-]*$/", $string)) {
        $result = true;
    }

    return $result;
}

In other words, just a standard regular expression with no Unicode trickery.  The ‘/u’ modifier would cause this to totally malfunction and match everything.  Good to know.

Constructive lies

Being a pathological liar myself, I often hear people saying how bad lies are and how lies are only making things worse.  Of course, there are counter examples of telling a lie to prevent hurting people and such.  But there weren’t so many examples of constructive, useful lies.  Here is one such example of lies used by an educator to assist students with a boring course.

The topic of Corporate Finance/Capital Markets is, even within the world of the Dismal Science, (Economics) an exceptionally dry and boring subject matter, encumbered by complex mathematic models and obscure economic theory.

What made Dr. K memorable was a gimmick he employed that began with his introduction at the beginning of his first class:

“Now I know some of you have already heard of me, but for the benefit of those who are unfamiliar, let me explain how I teach. Between today until the class right before finals, it is my intention to work into each of my lectures … one lie. Your job, as students, among other things, is to try and catch me in the Lie of the Day.

Read the whole story – it’s pretty fascinating.