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: èèéàù ...
- number开发者_JAVA百科s
- only one white space " "
I need dot NOT allow:
- any special characters like: |!"£$%&/()<> ...
Any ideas? Thanks for your help
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.
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
精彩评论