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!
Write Better JavaScript with Promises
You’ve probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don’t see what makes them so special. Can’t you just use a callback? What’s the big deal? In this article, we’ll…
Highlight Table Rows, Columns, and Cells Using MooTools 1.2.3
Row highlighting and individual cell highlighting in tables is pretty simple in every browser that supports :hover on all elements (basically everything except IE6). Column highlighting is a bit more difficult. Luckily MooTools 1.2.3 makes the process easy. The XHTML A normal table. The cells…
PHP Woot Checker – Tech, Wine, and Shirt Woot
If you haven’t heard of Woot.com, you’ve been living under a rock. For those who have been under the proverbial rock, here’s the plot: Every day, Woot sells one product. Once the item is sold out, no more items are available for purchase. You don’t know how many…