.NET Framework Bookmark and Share   
 index > Regular Expressions > Validate the text box control as get only characters
 

Validate the text box control as get only characters

i am using asp.net wiht c sharp. i want to validate the text box control as get only a-z, A-Z,. (dot) and space. how will doa

MRBponraj
[A-Za-z\.\s] +
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
  • Edited byJohnGrove Friday, September 04, 2009 2:12 PMAdded +
  •  
JohnGrove
Hehe, a little improvement

[A-Za-z\. ] +

1 if \r \n \t would not appear in a text box, then a space would be enough
2 if at least one character, a + needed.
www.wonderstudio.cn
Eping Wang
Yes, thank you!
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
JohnGrove
you can Add those charechters to an array.
on keydown event you can check the charachter typed in your textbox,
if your charachter is not in array ,set :
e.handeled = false;
Pishkari
pishkari
In ASP.NET, you will probably use the RegularExpressionValidator control, bound to your TextBox control. Look up the MSDN usage for more detail. You can use the Regular Expression patterns suggested above. My only additional input is that the RegularExpressionValidator control will treat an empty textbox as valid input (regardless of the pattern used). So, if you don't want to allow an empty input, you will need to test on either the client or server side for that condition. Other than that, the RegularExpressionValidator will do a nice job.
Les Potter, Xalnix Corporation, Yet Another C# Blog
xalnix

You can use google to search for other answers

Custom Search

More Threads

• Regular Expression in C#
• Better way of removing commas
• Question about lazy quantifier
• Gow to Generate output using RegEx
• Need Raguler Expression
• Delete second occurance of a word
• Exclude hyphenated words from word boundaries
• Regular Expression Performance and String Class
• Help Creating Regular Expressions
• Correction with a regular expression