Home » Development » How to allow European characters in text fields by using regular expression?

How to allow European characters in text fields by using regular expression?

You need input validation in your forms to keep your application secure. The best and easiest way to implement input validation is that using regular expressions (regex).

Here is a simple regex to make sure that only English alphabet is allowed in the text field for user’s first name:

<telerik:RadTextBox ID="txtFirstName" runat="server" Font-Size="Medium" Width="200px"></telerik:RadTextBox><span class="mandotaryField" title="Mandotary field"> *</span>
<asp:RegularExpressionValidator ID="regexFirstName" CssClass="ValidationMessage" SetFocusOnError="true" runat="server" Display="Dynamic" ValidationExpression="^[a-zA-Z]$" ControlToValidate="txtFirstName" ErrorMessage="Invalid name format"></asp:RegularExpressionValidator>

What if you want to allow more than English alphabet? Let’s say you have users from Europe so that you need your regex to accept European languages such as German, Italian, Spanish, Portuguese, Danish, Swedish, Irish, Albanian and more.

Use this regex to accept over 70 European (and some African) characters in your text field:

^[a-zA-Z\u00c0-\u017e]$

Here are the characters accepted by this regex:

ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿıŒœŠšŸŽž

More Information:

Ned Sahin

Blogger for 20 years. Former Microsoft Engineer. Author of six books. I love creating helpful content and sharing with the world. Reach me out for any questions or feedback.

2 thoughts on “How to allow European characters in text fields by using regular expression?”

Leave a Comment