G
Guest
How do I make sure that there are 10 numbers in a txtbox?
Justin Rogers said:10 numbers or 10 digits?
private bool Validate10Digits(TextBox text) {
if ( text.Length != 10 ) { return false; } // not 10 of them for sure
for(int i = 0; i < text.Length; i++) {
char trans = text - '0';
if ( trans < 0 || trans > 9 ) { return false; }
}
return true;
}
10 numbers is a variation of the above.
private bool Validate10Numbers(TextBox text) {
if ( text.Length < 19 ) { return false; } // basic check
string[] numbers = text.Split(',');
if ( numbers.Length != 10 ) { return false; }
for(int i = 0; i < numbers.Length; i++) {
if ( !ValidateNumber(i) ) { return false;
}
return true;
}
ValidateNumber is a variation of Validate10Digits that takes a string instead
of a TextBox and then removes the initial check.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
Dave said:How do I make sure that there are 10 numbers in a txtbox?
Dave said:How do I make sure that there are 10 numbers in a
txtbox?