txtBox help

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
How do I code in VB?

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?

Written from scratch:

\\\
Private Function ValidateInput(ByVal Text As String) As Boolean
If Text.Lengh <> 10 Then
Return False
End If
For Each c As Char In Text
If Not Char.IsDigit(c) Then
Return False
End If
Next c
Return True
End Function
///
 
Back
Top