Some useful TextBox Validations
2007-06-29 16:19
309 查看
Numeric TextBox
Numeric TextBox with Decimals
TextBox Allowing Characters Only
TextBox Allowing Upper Case Characters Only
TextBox Allowing Lower Case Characters Only
Check For Unfilled TextBox
http://www.codeproject.com/useritems/tips.asp#tip3.4.3
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( !( char.IsDigit( e.KeyChar ) || char.IsControl( e.KeyChar ) ) ) { e.Handled = true; } }
Numeric TextBox with Decimals
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( !( char.IsDigit( e.KeyChar) || char.IsControl( e.KeyChar ) ||(e.KeyChar== (char )46)) ) { e.Handled = true; } }
TextBox Allowing Characters Only
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( !( char.IsLetter( e.KeyChar ) || char.IsControl( e.KeyChar ) ) ) { e.Handled = true; } }
TextBox Allowing Upper Case Characters Only
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( !( char.IsUpper( e.KeyChar ) || char.IsControl( e.KeyChar )) ) { e.Handled = true; } }
TextBox Allowing Lower Case Characters Only
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( !( char.IsLower( e.KeyChar ) || char.IsControl( e.KeyChar )) ) { e.Handled = true; } }
Check For Unfilled TextBox
// Call this function and pass the Textbox as parameter to this function public static bool ChkEmpty(params System.Windows.Forms.TextBox[ ] tb) { int i; for (i = 0; i < tb.Length; i++) { if (tb[i].Text.Trim() == "") { MessageBox.Show("Don't keep field empty"); tb[i].Focus(); return false; } } return true; }
http://www.codeproject.com/useritems/tips.asp#tip3.4.3
相关文章推荐
- Some useful TextBox Validations
- Some useful link for Serial Listen and Forward
- Some useful commands on Ubuntu
- someuseful2
- 转载一个老外的编译错误hope useful to some one really need it
- Some useful techniques in sql injection [个人总结简洁版]
- some useful resources of Microsoft
- Here are some useful hints for reduce your C/C++ code dramatically
- some useful functions of c++
- Some useful tools for the Web Developer
- Some useful tips about sox rec
- some useful ffmpeg commands
- SQL Syntax - Some Useful Keywords
- Some Useful links
- Some useful Linux Commands
- [Java][DB][Cassandra] some useful link to understand the concepts of SSTable
- Java options --Some Useful -XX Options
- some useful command for openSuse
- Some useful linux commands
- Some useful URL for written English