Regular Expression for Alphabetic Letter with accent

北慕城南 提交于 2021-02-07 08:16:53

问题


I need a validation a texbox in c# and asp.net using Regular Expression.

I need allow:

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

I need dot NOT allow:

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

Any ideas? Thanks for your help


回答1:


If validation occurs at server side, you can use the pattern:

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

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

Note that \w also include the underscore and other word-connectors. You can use [\p{L}\p{Nd}] instead of \w to disallow them.

See also: Character Classes




回答2:


This might be a start

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

\d matches the digits

\w matches "word characters". The.NET RegEx considers unicode characters as word characters. See: http://regexlib.com/CheatSheet.aspx

I'm not sure what you mean by "one white space". This expressions allows one space, but not double-spaces, between words.



来源:https://stackoverflow.com/questions/4516756/regular-expression-for-alphabetic-letter-with-accent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!