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!
![7 Essential JavaScript Functions]()
I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener
and attachEvent
. Times have changed but there are still a few functions each developer should...
![Camera and Video Control with HTML5]()
Client-side APIs on mobile and desktop devices are quickly providing the same APIs. Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop. One of those APIs is the getUserMedia API...
![Shake Things Up Using jQuery UI’s Shake Effect]()
Yesterday I created a tutorial showing you how you can shake an element using Fx.Shake, a MooTools component written by Aaron Newton. It turns out that jQuery UI also has a shake effect which can draw attention to an element.
The XHTML
Exactly the same as...
![From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!]()
My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...