Regular Expression: Support for all languages

Introduction:

One of my friend came across a situation where I need to restrict a text control to support only alphabetic. So, we tried with very very simple regular expression;
/^[A-Za-z]*$.
Now the question arises whether this control also supports any other languages? If I change my setting to French, will this control supports?

Solution:

The above mentioned regular expression is not generic enough if it wants to match all those characters that are used in languages like French.

/^[\p{L}-. ]*$ This says:

^ -: Start of the string
[ ... ]* -: Zero or more of the following
\p{L} -: Unicode letter characters
- -: Dashes
. -: Periods
-: Spaces
$ -: End of the string

Keep coding... :-)

Comments

Popular posts from this blog

Interview Questions to Ask the Employer

Place .NET DLL in GAC

Windows Communication Foundation - FAQ