0

I want to write a regex expression which allows all the english alphabets and special characters for e.g

Abcdwfg*+""æ-/.,´Øøå&öé

And such string should not start with a number i mean number can come after any alphabet for e.g "Héllo123"

I tried this [a-zA-Z\s]{0,50} but it only accepts English small and capital letters, than i tried [\w\sØÖ]{0,100} but in this i have to explicitly write that these ØÖ characters should be allowed so i need some help here.

Here is the code where i am trying to do it

<asp:RegularExpressionValidator id="RegularExpressionValidator2" runat="server" ControlToValidate="ForlagName" ErrorMessage="Enter a valid ForlagName." Text="*" Display="Dynamic" ForeColor="Red" ValidationExpression="[a-zA-Z\s]{0,50}" ValidationGroup="vgForlagKey">
     </asp:RegularExpressionValidator> 
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Salman Shaykh
  • 221
  • 5
  • 16

2 Answers2

1

Mention the hexadecimal values or ranges for special character in regex character class and repeat the same regex again along with 0-9 to avoid starting of any string from any digit.

For example:

[A-Za-z\xf6-\xf8\xe5]+[A-Za-z\xf6-\xf8\xe50-9]*

Some example for hexadecimal values and their special character

f6 - ö 
f7 - ÷
f8 - ø
e5 - å
...

Online demo

Note: Use ^ and $ for matching starting and ending of the string/line if needed.

Read more...

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
0

Try this:

^[\D]{0,50}

\D is everything thats not a digit.

Florian Schmidinger
  • 4,682
  • 2
  • 16
  • 28