Match Accented Letters with Regular Expressions
Regular expressions are used for a variety of tasks but the one I see most often is input validation. Names, dates, numbers...we tend to use regular expressions for everything, even when we probably shouldn't.
The most common syntax for checking alphabetic characters is A-z
but what if the string contains accented characters? Characters like ğ
and Ö
will make the regex fail. That's where we need to use Unicode property escapes to check for a broader letter format!
Let's look at how we can use \p{Letter}
and the Unicode flag (u
) to match both standard and accented characters:
// Single word
"Özil".match(/[\p{Letter}]+/gu)
// Word with spaces
"Oğuzhan Özyakup".match(/[\p{Letter}\s]+/gu);
Using regular expressions to validate strings, especially names, is much more difficult than A-z+
. Names and other strings can be very diverse -- let's not insult users by making them provide non-accented letters just to pass validation!
![5 More HTML5 APIs You Didn’t Know Existed]()
The HTML5 revolution has provided us some awesome JavaScript and HTML APIs. Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers. Regardless of API strength or purpose, anything to help us better do our job is a...
![fetch API]()
One of the worst kept secrets about AJAX on the web is that the underlying API for it, XMLHttpRequest
, wasn't really made for what we've been using it for. We've done well to create elegant APIs around XHR but we know we can do better. Our effort to...
![CSS Circles]()
A while back I shared a clever technique for creating triangles with only CSS. Over the past year, I've found CSS triangles incredibly effective, especially when looking to create tooltips or design elements with a likewise pointer pattern. There's another common shape...
![MooTools dwCheckboxes Plugin]()
Update / Fix: The checkboxes will no longer toggle when the "mouseup" event doesn't occur on a checkbox.
Every morning I wake up to a bunch of emails in my Gmail inbox that I delete without reading. I end up clicking so many damn checkboxes...