Regular expression for the alphabet with an accent

I need a texbox check in C # and asp.net using regex.

I need to allow:

  • UPPERCASE alphabetic letters and lowercase letters or any ComBINAtion
  • accented type letters: èèéàù ...
  • the numbers
  • only one empty space ""

I need a point NOT to allow:

  • any special characters, such as: |! "£ $% & / () <> ...

Any ideas? Thank you for your help.

+4
source share
2 answers

If the check is done on the server side, you can use the template:

^\w*(\s\w*)?$ 

\w in .Net is Unicode - this should include all letters.

Note that \w also includes underscores and other dictionary connectors. You can use [\p{L}\p{Nd}] instead of \w to disable them.

See also: Character classes

+2
source

It could be the beginning

 ^([\w\d]+[ ]?)+$ 

\ d matches digits

\ w matches "word characters" .. NET RegEx treats Unicode characters as word characters. See: http://regexlib.com/CheatSheet.aspx

I'm not sure what you mean by "one white space." These expressions allow a single space, but not double spaces between words.

+3
source

Source: https://habr.com/ru/post/1333145/


All Articles