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.
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.
\\\
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
///
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.